当前位置: 首页>>代码示例>>Golang>>正文


Golang goblin.Goblin函数代码示例

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


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


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