Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
Signed-off-by: lucklove <gnu.crazier@gmail.com>
  • Loading branch information
lucklove committed Jul 18, 2020
1 parent eed9b07 commit 53a76d6
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
85 changes: 85 additions & 0 deletions pkg/repository/v1manifest/types_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
1 change: 1 addition & 0 deletions tests/tiup/tiup.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mirror = "https://tiup-mirrors.pingcap.com"

0 comments on commit 53a76d6

Please sign in to comment.