github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/depends/kit/httptransport/z_context_test.go (about) 1 package httptransport_test 2 3 import ( 4 "context" 5 "os" 6 "testing" 7 8 . "github.com/onsi/gomega" 9 10 "github.com/machinefi/w3bstream/pkg/depends/base/consts" 11 . "github.com/machinefi/w3bstream/pkg/depends/kit/httptransport" 12 ) 13 14 func TestServiceMeta(t *testing.T) { 15 meta := &ServiceMeta{} 16 17 name, version := "srv-test", "1.1.1" 18 19 os.Setenv(consts.EnvProjectName, name) 20 meta.SetDefault() 21 NewWithT(t).Expect(meta.String()).To(Equal(name)) 22 23 os.Setenv(consts.EnvProjectVersion, version) 24 meta.SetDefault() 25 NewWithT(t).Expect(meta.String()).To(Equal(name + "@" + version)) 26 } 27 28 func TestServiceMetaWithContext(t *testing.T) { 29 meta := ServiceMeta{Name: "test"} 30 ctx := ContextWithServiceMeta(context.Background(), meta) 31 got := ServiceMetaFromContext(ctx) 32 NewWithT(t).Expect(got).To(Equal(meta)) 33 } 34 35 var ( 36 bgctx = context.Background() 37 )