From c86d74e52df57963b79dde523f42c9dca94992d9 Mon Sep 17 00:00:00 2001 From: lucklove Date: Sat, 18 Jul 2020 14:52:05 +0800 Subject: [PATCH] Add test Signed-off-by: lucklove --- pkg/repository/v1manifest/types_test.go | 85 +++++++++++++++++++++++++ tests/tiup/tiup.toml | 1 + 2 files changed, 86 insertions(+) create mode 100644 pkg/repository/v1manifest/types_test.go create mode 100644 tests/tiup/tiup.toml diff --git a/pkg/repository/v1manifest/types_test.go b/pkg/repository/v1manifest/types_test.go new file mode 100644 index 0000000000..dd2a7cc6bc --- /dev/null +++ b/pkg/repository/v1manifest/types_test.go @@ -0,0 +1,85 @@ +// Copyright 2020 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// See the License for the specific language governing permissions and +// limitations under the License. + +package v1manifest + +import ( + "testing" + + "github.com/alecthomas/assert" +) + +func TestComponentList(t *testing.T) { + manifest := &Index{ + Components: map[string]ComponentItem{ + "comp1": ComponentItem{}, + "comp2": ComponentItem{Yanked: true}, + }, + } + + list := manifest.ComponentList() + assert.Equal(t, len(list), 1) + _, ok := list["comp1"] + assert.True(t, ok) + + list = manifest.ComponentListWithYanked() + assert.Equal(t, len(list), 2) + _, ok = list["comp1"] + assert.True(t, ok) + _, ok = list["comp2"] + assert.True(t, ok) +} + +func TestVersionList(t *testing.T) { + manifest := &Component{ + Platforms: map[string]map[string]VersionItem{ + "linux/amd64": { + "v1.0.0": {Entry: "test"}, + "v1.1.1": {Entry: "test", Yanked: true}, + }, + "any/any": { + "v1.0.0": {Entry: "test"}, + "v1.1.1": {Entry: "test", Yanked: true}, + }, + }, + } + + versions := manifest.VersionList("linux/amd64") + assert.Equal(t, len(versions), 1) + _, ok := versions["v1.0.0"] + assert.True(t, ok) + + versions = manifest.VersionListWithYanked("linux/amd64") + assert.Equal(t, len(versions), 2) + _, ok = versions["v1.0.0"] + assert.True(t, ok) + _, ok = versions["v1.1.1"] + assert.True(t, ok) + + versions = manifest.VersionList("windows/amd64") + assert.Equal(t, len(versions), 1) + _, ok = versions["v1.0.0"] + assert.True(t, ok) + + manifest = &Component{ + Platforms: map[string]map[string]VersionItem{ + "linux/amd64": { + "v1.0.0": {Entry: "test"}, + "v1.1.1": {Entry: "test", Yanked: true}, + }, + }, + } + + versions = manifest.VersionList("windows/amd64") + assert.Equal(t, len(versions), 0) +} diff --git a/tests/tiup/tiup.toml b/tests/tiup/tiup.toml new file mode 100644 index 0000000000..598fc52376 --- /dev/null +++ b/tests/tiup/tiup.toml @@ -0,0 +1 @@ +mirror = "https://tiup-mirrors.pingcap.com"