• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang goblin.Goblin函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/franela/goblin.Goblin函数的典型用法代码示例。如果您正苦于以下问题:Golang Goblin函数的具体用法?Golang Goblin怎么用?Golang Goblin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Goblin函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestSpec

func TestSpec(t *testing.T) {
	g := goblin.Goblin(t)

	g.Describe("Spec file", func() {

		g.Describe("when looking up a container", func() {

			spec := Spec{}
			spec.Containers = append(spec.Containers, &Container{
				Name: "golang",
			})

			g.It("should find and return the container", func() {
				c, err := spec.lookupContainer("golang")
				g.Assert(err == nil).IsTrue("error should be nil")
				g.Assert(c).Equal(spec.Containers[0])
			})

			g.It("should return an error when not found", func() {
				c, err := spec.lookupContainer("node")
				g.Assert(err == nil).IsFalse("should return error")
				g.Assert(c == nil).IsTrue("should return nil container")
			})

		})
	})
}
开发者ID:tnaoto,项目名称:drone,代码行数:27,代码来源:spec_test.go


示例2: TestCache

func TestCache(t *testing.T) {

	g := goblin.Goblin(t)
	g.Describe("Cache", func() {

		var c *gin.Context
		g.BeforeEach(func() {
			c = new(gin.Context)
			ToContext(c, Default())
		})

		g.It("Should set and get an item", func() {
			Set(c, "foo", "bar")
			v, e := Get(c, "foo")
			g.Assert(v).Equal("bar")
			g.Assert(e == nil).IsTrue()
		})

		g.It("Should return nil when item not found", func() {
			v, e := Get(c, "foo")
			g.Assert(v == nil).IsTrue()
			g.Assert(e == nil).IsFalse()
		})
	})
}
开发者ID:ZombieHippie,项目名称:drone,代码行数:25,代码来源:cache_test.go


示例3: Test_shell

func Test_shell(t *testing.T) {

	g := goblin.Goblin(t)
	g.Describe("shell containers", func() {

		g.It("should ignore plugin steps", func() {
			root := parse.NewRootNode()
			c := root.NewPluginNode()
			c.Container = runner.Container{}
			ops := NewShellOp(Linux_adm64)
			ops.VisitContainer(c)

			g.Assert(len(c.Container.Entrypoint)).Equal(0)
			g.Assert(len(c.Container.Command)).Equal(0)
			g.Assert(c.Container.Environment["DRONE_SCRIPT"]).Equal("")
		})

		g.It("should set entrypoint, command and environment variables", func() {
			root := parse.NewRootNode()
			root.Base = "/go"
			root.Path = "/go/src/github.com/octocat/hello-world"

			c := root.NewShellNode()
			c.Commands = []string{"go build"}
			ops := NewShellOp(Linux_adm64)
			ops.VisitContainer(c)

			g.Assert(c.Container.Entrypoint).Equal([]string{"/bin/sh", "-c"})
			g.Assert(c.Container.Command).Equal([]string{"echo $DRONE_SCRIPT | base64 -d | /bin/sh -e"})
			g.Assert(c.Container.Environment["DRONE_SCRIPT"] != "").IsTrue()
		})
	})
}
开发者ID:tnaoto,项目名称:drone,代码行数:33,代码来源:shell_test.go


示例4: TestBlobstore

func TestBlobstore(t *testing.T) {
	db := datasql.MustConnect("sqlite3", ":memory:")
	bs := New(db)

	g := goblin.Goblin(t)
	g.Describe("Blobstore", func() {

		// before each test be sure to purge the blob
		// table data from the database.
		g.Before(func() {
			db.Exec("DELETE FROM blobs")
		})

		g.It("Should Put a Blob", func() {
			err := bs.Put("foo", []byte("bar"))
			g.Assert(err == nil).IsTrue()
		})

		g.It("Should Put a Blob reader", func() {
			var buf bytes.Buffer
			buf.Write([]byte("bar"))
			err := bs.PutReader("foo", &buf)
			g.Assert(err == nil).IsTrue()
		})

		g.It("Should Overwrite a Blob", func() {
			bs.Put("foo", []byte("bar"))
			bs.Put("foo", []byte("baz"))
			blob, err := bs.Get("foo")
			g.Assert(err == nil).IsTrue()
			g.Assert(string(blob)).Equal("baz")
		})

		g.It("Should Get a Blob", func() {
			bs.Put("foo", []byte("bar"))
			blob, err := bs.Get("foo")
			g.Assert(err == nil).IsTrue()
			g.Assert(string(blob)).Equal("bar")
		})

		g.It("Should Get a Blob reader", func() {
			bs.Put("foo", []byte("bar"))
			r, _ := bs.GetReader("foo")
			blob, _ := ioutil.ReadAll(r)
			g.Assert(string(blob)).Equal("bar")
		})

		g.It("Should Del a Blob", func() {
			bs.Put("foo", []byte("bar"))
			err := bs.Del("foo")
			g.Assert(err == nil).IsTrue()
		})

		g.It("Should create a Context", func() {
			c := NewContext(context.Background(), db)
			b := blobstore.FromContext(c).(*Blobstore)
			g.Assert(b.DB).Equal(db)
		})
	})
}
开发者ID:drone,项目名称:drone-dart,代码行数:60,代码来源:blobstore_test.go


示例5: TestUsers

func TestUsers(t *testing.T) {
	gin.SetMode(gin.TestMode)
	logrus.SetOutput(ioutil.Discard)

	g := goblin.Goblin(t)

	g.Describe("User endpoint", func() {
		g.It("Should return the authenticated user", func() {

			e := gin.New()
			e.NoRoute(GetUser)
			e.Use(func(c *gin.Context) {
				c.Set("user", fakeUser)
			})

			w := httptest.NewRecorder()
			r, _ := http.NewRequest("GET", "/", nil)
			e.ServeHTTP(w, r)

			want, _ := json.Marshal(fakeUser)
			got := strings.TrimSpace(w.Body.String())
			g.Assert(got).Equal(string(want))
			g.Assert(w.Code).Equal(200)
		})
	})
}
开发者ID:jonbodner,项目名称:lgtm,代码行数:26,代码来源:user_test.go


示例6: Test_Matrix

func Test_Matrix(t *testing.T) {

	g := goblin.Goblin(t)
	g.Describe("Calculate matrix", func() {

		axis, _ := Parse(fakeMatrix)

		g.It("Should calculate permutations", func() {
			g.Assert(len(axis)).Equal(24)
		})

		g.It("Should not duplicate permutations", func() {
			set := map[string]bool{}
			for _, perm := range axis {
				set[perm.String()] = true
			}
			g.Assert(len(set)).Equal(24)
		})

		g.It("Should return nil if no matrix", func() {
			axis, err := Parse("")
			g.Assert(err == nil).IsTrue()
			g.Assert(axis == nil).IsTrue()
		})
	})
}
开发者ID:fclairamb,项目名称:drone,代码行数:26,代码来源:matrix_test.go


示例7: Test_RealClient

func Test_RealClient(t *testing.T) {

	g := goblin.Goblin(t)
	g.Describe("Real Dart Client", func() {
		// These tests will use the LIVE Dart URLs
		// for integration testing purposes.
		//
		// Note that an outage or network connectivity
		// issues could result in false positives.
		c := NewClientDefault()

		g.It("Should Get a Version", func() {
			sdk, err := c.GetSDK()
			g.Assert(err == nil).IsTrue()
			g.Assert(sdk.Version == "").IsFalse()
			g.Assert(sdk.Revision == "").IsFalse()
		})

		g.It("Should Get a Package", func() {
			pkg, err := c.GetPackage("angular")
			g.Assert(err == nil).IsTrue()
			g.Assert(pkg.Name).Equal("angular")
			g.Assert(pkg.Latest != nil).IsTrue()
		})

		g.It("Should Get a Recent Package List", func() {
			pkgs, err := c.GetPackageRecent()
			g.Assert(err == nil).IsTrue()
			g.Assert(len(pkgs)).Equal(100)
		})
	})
}
开发者ID:Guoshusheng,项目名称:drone-dart,代码行数:32,代码来源:client_test.go


示例8: TestParseForwardedHeadersProto

func TestParseForwardedHeadersProto(t *testing.T) {
	g := goblin.Goblin(t)

	g.Describe("Parse proto Forwarded Headers", func() {
		g.It("Should parse a normal proto Forwarded header", func() {
			parsedHeader := parseHeader(mockRequest, "Forwarded", "proto")
			g.Assert("https" == parsedHeader[0]).IsTrue()
		})
		g.It("Should parse a normal for Forwarded header", func() {
			parsedHeader := parseHeader(mockRequest, "Forwarded", "for")
			g.Assert(reflect.DeepEqual([]string{"110.0.2.2", "\"[::1]\"", "10.2.3.4"}, parsedHeader)).IsTrue()
		})
		g.It("Should parse a normal host Forwarded header", func() {
			parsedHeader := parseHeader(mockRequest, "Forwarded", "host")
			g.Assert("example.com" == parsedHeader[0]).IsTrue()
		})
		g.It("Should parse a normal by Forwarded header", func() {
			parsedHeader := parseHeader(mockRequest, "Forwarded", "by")
			g.Assert("127.0.0.1" == parsedHeader[0]).IsTrue()
		})
		g.It("Should not crash if a wrongly formed Forwarder header is sent", func() {
			parsedHeader := parseHeader(wronglyFormedRequest, "Forwarded", "by")
			g.Assert(len(parsedHeader) == 0).IsTrue()
		})
	})
}
开发者ID:fclairamb,项目名称:drone,代码行数:26,代码来源:location_test.go


示例9: TestParallelNode

func TestParallelNode(t *testing.T) {
	g := goblin.Goblin(t)

	g.Describe("ParallelNode", func() {
		g.It("should append nodes", func() {
			node := NewRunNode()

			parallel0 := NewParallelNode()
			parallel1 := parallel0.Append(node)
			g.Assert(parallel0.Type().String()).Equal(NodeParallel)
			g.Assert(parallel0.Body[0]).Equal(node)
			g.Assert(parallel0).Equal(parallel1)
		})

		g.It("should fail validation when invalid type", func() {
			node := ParallelNode{}
			err := node.Validate()
			g.Assert(err == nil).IsFalse()
			g.Assert(err.Error()).Equal("Parallel Node uses an invalid type")
		})

		g.It("should fail validation when empty body", func() {
			node := NewParallelNode()
			err := node.Validate()
			g.Assert(err == nil).IsFalse()
			g.Assert(err.Error()).Equal("Parallel Node body is empty")
		})

		g.It("should pass validation", func() {
			node := NewParallelNode().Append(NewRunNode())
			g.Assert(node.Validate() == nil).IsTrue()
		})
	})
}
开发者ID:tnaoto,项目名称:drone,代码行数:34,代码来源:node_parallel_test.go


示例10: TestBuildNode

func TestBuildNode(t *testing.T) {
	g := goblin.Goblin(t)

	g.Describe("Build", func() {
		g.Describe("given a yaml file", func() {

			g.It("should unmarshal", func() {
				in := []byte(".")
				out := build{}
				err := yaml.Unmarshal(in, &out)
				if err != nil {
					g.Fail(err)
				}
				g.Assert(out.Context).Equal(".")
			})

			g.It("should unmarshal shorthand", func() {
				in := []byte("{ context: ., dockerfile: Dockerfile }")
				out := build{}
				err := yaml.Unmarshal(in, &out)
				if err != nil {
					g.Fail(err)
				}
				g.Assert(out.Context).Equal(".")
				g.Assert(out.Dockerfile).Equal("Dockerfile")
			})
		})
	})
}
开发者ID:tnaoto,项目名称:drone,代码行数:29,代码来源:node_build_test.go


示例11: Test_Inject

func Test_Inject(t *testing.T) {

	g := goblin.Goblin(t)
	g.Describe("Inject params", func() {

		g.It("Should replace vars with $$", func() {
			s := "echo $$FOO $BAR"
			m := map[string]string{}
			m["FOO"] = "BAZ"
			g.Assert("echo BAZ $BAR").Equal(Inject(s, m))
		})

		g.It("Should not replace vars with single $", func() {
			s := "echo $FOO $BAR"
			m := map[string]string{}
			m["FOO"] = "BAZ"
			g.Assert(s).Equal(Inject(s, m))
		})

		g.It("Should not replace vars in nil map", func() {
			s := "echo $$FOO $BAR"
			g.Assert(s).Equal(Inject(s, nil))
		})
	})
}
开发者ID:carnivalmobile,项目名称:drone,代码行数:25,代码来源:inject_test.go


示例12: TestRecoverNode

func TestRecoverNode(t *testing.T) {
	g := goblin.Goblin(t)

	g.Describe("RecoverNode", func() {
		g.It("should set body", func() {
			node0 := NewRunNode()

			recover0 := NewRecoverNode()
			recover1 := recover0.SetBody(node0)
			g.Assert(recover0.Type().String()).Equal(NodeRecover)
			g.Assert(recover0.Body).Equal(node0)
			g.Assert(recover0).Equal(recover1)
		})

		g.It("should fail validation when invalid type", func() {
			recover0 := RecoverNode{}
			err := recover0.Validate()
			g.Assert(err == nil).IsFalse()
			g.Assert(err.Error()).Equal("Recover Node uses an invalid type")
		})

		g.It("should fail validation when empty body", func() {
			recover0 := NewRecoverNode()
			err := recover0.Validate()
			g.Assert(err == nil).IsFalse()
			g.Assert(err.Error()).Equal("Recover Node body is empty")
		})

		g.It("should pass validation", func() {
			recover0 := NewRecoverNode()
			recover0.SetBody(NewRunNode())
			g.Assert(recover0.Validate() == nil).IsTrue()
		})
	})
}
开发者ID:tnaoto,项目名称:drone,代码行数:35,代码来源:node_recover_test.go


示例13: Test_args

func Test_args(t *testing.T) {

	g := goblin.Goblin(t)
	g.Describe("plugins arguments", func() {

		g.It("should ignore non-plugin containers", func() {
			root := parse.NewRootNode()
			c := root.NewShellNode()
			c.Container = runner.Container{}
			c.Vargs = map[string]interface{}{
				"depth": 50,
			}

			ops := NewArgsOp()
			ops.VisitContainer(c)

			g.Assert(c.Container.Environment["PLUGIN_DEPTH"]).Equal("")
		})

		g.It("should include args as environment variable", func() {
			root := parse.NewRootNode()
			c := root.NewPluginNode()
			c.Container = runner.Container{}
			c.Vargs = map[string]interface{}{
				"depth": 50,
			}

			ops := NewArgsOp()
			ops.VisitContainer(c)

			g.Assert(c.Container.Environment["PLUGIN_DEPTH"]).Equal("50")
		})
	})

}
开发者ID:tnaoto,项目名称:drone,代码行数:35,代码来源:args_test.go


示例14: Test_normalize

func Test_normalize(t *testing.T) {

	g := goblin.Goblin(t)
	g.Describe("normalizing", func() {

		g.Describe("images", func() {

			g.It("should append tag if empty", func() {
				c := newConfig(&yaml.Container{
					Image: "golang",
				})

				ImageTag(c)
				g.Assert(c.Pipeline[0].Image).Equal("golang:latest")
			})

			g.It("should not override existing tag", func() {
				c := newConfig(&yaml.Container{
					Image: "golang:1.5",
				})

				ImageTag(c)
				g.Assert(c.Pipeline[0].Image).Equal("golang:1.5")
			})
		})
	})
}
开发者ID:donny-dont,项目名称:drone,代码行数:27,代码来源:image_test.go


示例15: Test_pull

func Test_pull(t *testing.T) {
	root := parse.NewRootNode()

	g := goblin.Goblin(t)
	g.Describe("pull image", func() {

		g.It("should be enabled for plugins", func() {
			c := root.NewPluginNode()
			c.Container = runner.Container{}
			op := NewPullOp(true)

			op.VisitContainer(c)
			g.Assert(c.Container.Pull).IsTrue()
		})

		g.It("should be disabled for plugins", func() {
			c := root.NewPluginNode()
			c.Container = runner.Container{}
			op := NewPullOp(false)

			op.VisitContainer(c)
			g.Assert(c.Container.Pull).IsFalse()
		})

		g.It("should be disabled for non-plugins", func() {
			c := root.NewShellNode()
			c.Container = runner.Container{}
			op := NewPullOp(true)

			op.VisitContainer(c)
			g.Assert(c.Container.Pull).IsFalse()
		})
	})
}
开发者ID:tnaoto,项目名称:drone,代码行数:34,代码来源:pull_test.go


示例16: TestSubstitution

func TestSubstitution(t *testing.T) {

	g := goblin.Goblin(t)
	g.Describe("Parameter Substitution", func() {

		g.It("Should substitute simple parameters", func() {
			before := "echo ${GREETING} WORLD"
			after := "echo HELLO WORLD"
			g.Assert(substitute(before, "GREETING", "HELLO")).Equal(after)
		})

		g.It("Should substitute quoted parameters", func() {
			before := "echo \"${GREETING}\" WORLD"
			after := "echo \"HELLO\" WORLD"
			g.Assert(substituteQ(before, "GREETING", "HELLO")).Equal(after)
		})

		g.It("Should substitute parameters and trim prefix", func() {
			before := "echo ${GREETING##asdf} WORLD"
			after := "echo HELLO WORLD"
			g.Assert(substitutePrefix(before, "GREETING", "asdfHELLO")).Equal(after)
		})

		g.It("Should substitute parameters and trim suffix", func() {
			before := "echo ${GREETING%%asdf} WORLD"
			after := "echo HELLO WORLD"
			g.Assert(substituteSuffix(before, "GREETING", "HELLOasdf")).Equal(after)
		})

		g.It("Should substitute parameters without using the default", func() {
			before := "echo ${GREETING=HOLA} WORLD"
			after := "echo HELLO WORLD"
			g.Assert(substituteDefault(before, "GREETING", "HELLO")).Equal(after)
		})

		g.It("Should substitute parameters using the a default", func() {
			before := "echo ${GREETING=HOLA} WORLD"
			after := "echo HOLA WORLD"
			g.Assert(substituteDefault(before, "GREETING", "")).Equal(after)
		})

		g.It("Should substitute parameters with replacement", func() {
			before := "echo ${GREETING/HE/A} MONDE"
			after := "echo ALLO MONDE"
			g.Assert(substituteReplace(before, "GREETING", "HELLO")).Equal(after)
		})

		g.It("Should substitute parameters with left substr", func() {
			before := "echo ${FOO:4} IS COOL"
			after := "echo THIS IS COOL"
			g.Assert(substituteLeft(before, "FOO", "THIS IS A REALLY LONG STRING")).Equal(after)
		})

		g.It("Should substitute parameters with substr", func() {
			before := "echo ${FOO:8:5} IS COOL"
			after := "echo DRONE IS COOL"
			g.Assert(substituteSubstr(before, "FOO", "THIS IS DRONE CI")).Equal(after)
		})
	})
}
开发者ID:Guoshusheng,项目名称:drone-exec,代码行数:60,代码来源:func_test.go


示例17: TestContainer

func TestContainer(t *testing.T) {
	g := goblin.Goblin(t)

	g.Describe("Container validation", func() {

		g.It("fails with an invalid name", func() {
			c := Container{
				Image: "golang:1.5",
			}
			err := c.Validate()
			g.Assert(err != nil).IsTrue()
			g.Assert(err.Error()).Equal("Missing container name")
		})

		g.It("fails with an invalid image", func() {
			c := Container{
				Name: "container_0",
			}
			err := c.Validate()
			g.Assert(err != nil).IsTrue()
			g.Assert(err.Error()).Equal("Missing container image")
		})

		g.It("passes with valid attributes", func() {
			c := Container{
				Name:  "container_0",
				Image: "golang:1.5",
			}
			g.Assert(c.Validate() == nil).IsTrue()
		})
	})
}
开发者ID:tnaoto,项目名称:drone,代码行数:32,代码来源:container_test.go


示例18: test_Stash

func test_Stash(t *testing.T) {
	g := goblin.Goblin(t)
	g.Describe("Stash Plugin", func() {

		g.It("Should return correct kind", func() {
			var s = &Stash{URL: "https://stash.atlassian.com"}
			g.Assert(s.GetKind()).Equal(model.RemoteStash)
		})

		g.It("Should parse hostname", func() {
			var s = &Stash{URL: "https://stash.atlassian.com"}
			g.Assert(s.GetHost()).Equal("stash.atlassian.com")
		})

		g.It("Should authorize user")

		g.It("Should get repos")

		g.It("Should get script/file")

		g.It("Should activate the repo")

		g.It("Should parse commit hook")
	})
}
开发者ID:reinbach,项目名称:drone,代码行数:25,代码来源:stash_test.go


示例19: TestSetPerm

func TestSetPerm(t *testing.T) {
	g := goblin.Goblin(t)
	g.Describe("SetPerm", func() {
		g.BeforeEach(func() {
			os.Unsetenv("PUBLIC_MODE")
		})
		g.It("Should set pull to false (private repo, user not logged in)", func() {
			c := gin.Context{}
			c.Set("repo", &model.Repo{
				IsPrivate: true,
			})
			SetPerm()(&c)
			v, ok := c.Get("perm")
			g.Assert(ok).IsTrue("perm was not set")
			p, ok := v.(*model.Perm)
			g.Assert(ok).IsTrue("perm was the wrong type")
			g.Assert(p.Pull).IsFalse("pull should be false")
		})
		g.It("Should set pull to true (private repo, user not logged in, public mode)", func() {
			os.Setenv("PUBLIC_MODE", "true")
			c := gin.Context{}
			c.Set("repo", &model.Repo{
				IsPrivate: true,
			})
			SetPerm()(&c)
			v, ok := c.Get("perm")
			g.Assert(ok).IsTrue("perm was not set")
			p, ok := v.(*model.Perm)
			g.Assert(ok).IsTrue("perm was the wrong type")
			g.Assert(p.Pull).IsTrue("pull should be true")
		})
	})
}
开发者ID:Zhomart,项目名称:drone,代码行数:33,代码来源:repo_test.go


示例20: TestMapEqualSlice

func TestMapEqualSlice(t *testing.T) {
	g := goblin.Goblin(t)

	g.Describe("Yaml map equal slice", func() {

		g.It("should unmarshal a map", func() {
			in := []byte("foo: bar")
			out := MapEqualSlice{}
			err := yaml.Unmarshal(in, &out)
			if err != nil {
				g.Fail(err)
			}
			g.Assert(len(out.Map())).Equal(1)
			g.Assert(out.Map()["foo"]).Equal("bar")
		})

		g.It("should unmarshal a map equal slice", func() {
			in := []byte("[ foo=bar ]")
			out := MapEqualSlice{}
			err := yaml.Unmarshal(in, &out)
			if err != nil {
				g.Fail(err)
			}
			g.Assert(len(out.parts)).Equal(1)
			g.Assert(out.parts["foo"]).Equal("bar")
		})

		g.It("should throw error when invalid map equal slice", func() {
			in := []byte("foo") // string value should fail parse
			out := MapEqualSlice{}
			err := yaml.Unmarshal(in, &out)
			g.Assert(err != nil).IsTrue("expects error")
		})
	})
}
开发者ID:Ablu,项目名称:drone,代码行数:35,代码来源:map_test.go



注:本文中的github.com/franela/goblin.Goblin函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang goreq.Request类代码示例发布时间:2022-05-23
下一篇:
Golang cc.Expr类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap