예제 #1
0
func TestNextBadVersionData(t *testing.T) {
	vs := Versions{
		Version{
			Version:   "1",
			Published: true,
		},
		Version{
			Version:   "2",
			Published: false,
			Required:  true, // Required but not Published makes no sense
		},
	}

	next, err := vs.Next("1")
	assert.Equal(t, "", next)
	assert.EqualError(t, err, `current version "1" is latest`)

	vs = Versions{
		Version{
			Version:   "1",
			Published: false,
		},
		Version{
			Version:   "2",
			Published: false, // nothing Published is not helpful
		},
	}

	latest, err := vs.Latest()
	assert.Equal(t, "", latest.Version)
	assert.EqualError(t, err, `no published versions`)
}
예제 #2
0
func TestNext(t *testing.T) {
	vs := Versions{
		Version{
			Version:   "1",
			Published: true,
		},
		Version{
			Version:   "2",
			Published: false,
		},
		Version{
			Version:   "3",
			Published: true,
		},
		Version{
			Version:   "4",
			Published: true,
			Required:  true,
		},
		Version{
			Version:   "5",
			Published: true,
			Required:  true,
		},
		Version{
			Version:   "6",
			Published: true,
		},
		Version{
			Version:   "7",
			Published: true,
		},
		Version{
			Version:   "8",
			Published: true,
		},
		Version{
			Version:   "9",
			Published: false,
		},
	}

	next, err := vs.Next("10")
	assert.Equal(t, "", next)
	assert.EqualError(t, err, `current version "10" not found`)

	next, err = vs.Next("1")
	assert.Equal(t, "4", next, "from version 1, next required version is 4")
	assert.Nil(t, err)

	next, err = vs.Next("4")
	assert.Equal(t, "5", next, "from version 4, next required version is 5")
	assert.Nil(t, err)

	next, err = vs.Next("5")
	assert.Equal(t, "8", next, "from version 5, latest published version is 8")
	assert.Nil(t, err)

	next, err = vs.Next("8")
	assert.Equal(t, "", next)
	assert.EqualError(t, err, `current version "8" is latest`)
}