123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- package v2
- import (
- "context"
- "testing"
- "go-common/app/infra/config/conf"
- "go-common/app/infra/config/model"
- "github.com/BurntSushi/toml"
- . "github.com/smartystreets/goconvey/convey"
- )
- func svr(t *testing.T) *Service {
- var (
- confPath = "../../cmd/config-service-example.toml"
- conf *conf.Config
- )
- Convey("get apply", t, func() {
- _, err := toml.DecodeFile(confPath, &conf)
- So(err, ShouldBeNil)
- })
- return New(conf)
- }
- func TestService_CheckVersion(t *testing.T) {
- var (
- c = context.TODO()
- svrName = "2888_dev_sh001"
- hostname = "test_host"
- bver = "server-1"
- ip = "123"
- version = int64(-1)
- token = "47fbbf237b7f11e8992154e1ad15006a"
- appoint = int64(-1)
- )
- svr := svr(t)
- Convey("AppService", t, func() {
- tmp, err := svr.AppService("sh001", "dev", "47fbbf237b7f11e8992154e1ad15006a")
- So(err, ShouldBeNil)
- So(tmp, ShouldEqual, svrName)
- })
- rhost := &model.Host{Service: svrName, Name: hostname, BuildVersion: bver, IP: ip, ConfigVersion: version, Appoint: appoint, Customize: "test"}
- Convey("get tag id by name", t, func() {
- event, err := svr.CheckVersion(c, rhost, token)
- So(err, ShouldBeNil)
- So(event, ShouldNotBeEmpty)
- Convey("get tag id by name", func() {
- e := <-event
- So(e, ShouldNotBeEmpty)
- })
- })
- }
- func TestService_Hosts(t *testing.T) {
- var (
- svrName = "2888_dev_sh001"
- )
- svr := svr(t)
- Convey("AppService", t, func() {
- tmp, err := svr.AppService("sh001", "dev", "47fbbf237b7f11e8992154e1ad15006a")
- So(err, ShouldBeNil)
- So(tmp, ShouldEqual, svrName)
- })
- Convey("should get hosts", t, func() {
- _, err := svr.Hosts(context.TODO(), svrName)
- So(err, ShouldBeNil)
- })
- }
- func TestService_Config(t *testing.T) {
- var (
- c = context.TODO()
- svrName = "2888_dev_sh001"
- version = int64(49)
- token = "47fbbf237b7f11e8992154e1ad15006a"
- )
- svr := svr(t)
- Convey("AppService", t, func() {
- tmp, err := svr.AppService("sh001", "dev", "47fbbf237b7f11e8992154e1ad15006a")
- So(err, ShouldBeNil)
- So(tmp, ShouldEqual, svrName)
- })
- Convey("should get hosts", t, func() {
- conf, err := svr.Config(c, svrName, token, version, nil)
- So(err, ShouldBeNil)
- So(conf, ShouldNotBeEmpty)
- })
- }
- func TestService_Push(t *testing.T) {
- var (
- c = context.TODO()
- svrName = "2888_dev_sh001"
- bver = "server-1"
- version = int64(49)
- )
- svr := svr(t)
- Convey("AppService", t, func() {
- tmp, err := svr.AppService("sh001", "dev", "47fbbf237b7f11e8992154e1ad15006a")
- So(err, ShouldBeNil)
- So(tmp, ShouldEqual, svrName)
- })
- service := &model.Service{Name: svrName, BuildVersion: bver, Version: version}
- Convey("should get Config2", t, func() {
- err := svr.Push(c, service)
- So(err, ShouldBeNil)
- })
- }
- func TestService_SetToken(t *testing.T) {
- var (
- svrName = "2888_dev_sh001"
- token = "47fbbf237b7f11e8992154e1ad15006a"
- )
- svr := svr(t)
- Convey("AppService", t, func() {
- tmp, err := svr.AppService("sh001", "dev", "47fbbf237b7f11e8992154e1ad15006a")
- So(err, ShouldBeNil)
- So(tmp, ShouldEqual, svrName)
- })
- Convey("should get Config2", t, func() {
- svr.SetToken(svrName, token)
- })
- }
- func TestService_ClearHost(t *testing.T) {
- var (
- c = context.TODO()
- svrName = "2888_dev_sh001"
- )
- svr := svr(t)
- Convey("AppService", t, func() {
- tmp, err := svr.AppService("sh001", "dev", "47fbbf237b7f11e8992154e1ad15006a")
- So(err, ShouldBeNil)
- So(tmp, ShouldEqual, svrName)
- })
- Convey("should clear host", t, func() {
- err := svr.ClearHost(c, svrName)
- So(err, ShouldBeNil)
- })
- }
- func TestService_VersionSuccess(t *testing.T) {
- var (
- c = context.TODO()
- svrName = "2888_dev_sh001"
- bver = "server-1"
- )
- svr := svr(t)
- Convey("AppService", t, func() {
- tmp, err := svr.AppService("sh001", "dev", "47fbbf237b7f11e8992154e1ad15006a")
- So(err, ShouldBeNil)
- So(tmp, ShouldEqual, svrName)
- })
- Convey("should clear host", t, func() {
- vers, err := svr.VersionSuccess(c, svrName, bver)
- So(err, ShouldBeNil)
- So(vers, ShouldNotBeEmpty)
- })
- }
- func TestService_Builds(t *testing.T) {
- var (
- c = context.TODO()
- svrName = "2888_dev_sh001"
- err error
- builds []string
- tmp string
- )
- svr := svr(t)
- Convey("AppService", t, func() {
- tmp, err = svr.AppService("sh001", "dev", "47fbbf237b7f11e8992154e1ad15006a")
- So(err, ShouldBeNil)
- So(tmp, ShouldEqual, svrName)
- })
- Convey("should clear host", t, func() {
- builds, err = svr.Builds(c, svrName)
- So(err, ShouldBeNil)
- So(builds, ShouldNotBeEmpty)
- })
- }
- func TestService_File(t *testing.T) {
- var (
- c = context.TODO()
- svrName = "2888_dev_sh001"
- bver = "server-1"
- fileName = "test.toml"
- token = "47fbbf237b7f11e8992154e1ad15006a"
- ver = int64(49)
- err error
- tmp string
- )
- svr := svr(t)
- Convey("AppService", t, func() {
- tmp, err = svr.AppService("sh001", "dev", "47fbbf237b7f11e8992154e1ad15006a")
- So(err, ShouldBeNil)
- So(tmp, ShouldEqual, svrName)
- })
- service := &model.Service{Name: svrName, BuildVersion: bver, File: fileName, Token: token, Version: ver}
- Convey("should clear host", t, func() {
- _, err = svr.File(c, service)
- So(err, ShouldBeNil)
- })
- }
|