Skip to content

Fixes some unit tests to be able to run them on windows#906

Closed
vdemeester wants to merge 1 commit intodocker:masterfrom
vdemeester:fix-some-windows-unit-tests
Closed

Fixes some unit tests to be able to run them on windows#906
vdemeester wants to merge 1 commit intodocker:masterfrom
vdemeester:fix-some-windows-unit-tests

Conversation

@vdemeester
Copy link
Collaborator

Some of them are skipped for now (because the feature is not supported
or needs more work), some of them are fixed.

There is still some errors, but it's a start 👼 🙏

Signed-off-by: Vincent Demeester [email protected]

)

func TestRunBuildResetsUidAndGidInContext(t *testing.T) {
skip.IfCondition(t, runtime.GOOS == "windows", "uid and gid not relevant on windows")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is actually not relevant as assert.Equal(t, uint32(0), fileInfo.Sys().(*syscall.Stat_t).Uid) doesn't compile under windows… I should remove that skip completely.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this file already skipped on Windows?

"testing"

"github.com/gotestyourself/gotestyourself/skip"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh 😓

expectedMsg: "Unexpected",
},
{
// FIXME(vdemeester) that doesn't work under windows, the check needs to be smarter
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tests fails under Windows because of : 7f53c99#r27815425

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the info endpoint could be queried instead of making the assumption that daemon os/platform == client os/platform

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitely, but probably need to be "skipped" for now, and follow-up on a fix PR for that problem only 👼

@vdemeester vdemeester force-pushed the fix-some-windows-unit-tests branch from e39587d to f7f4172 Compare February 27, 2018 16:08
@codecov-io
Copy link

codecov-io commented Feb 27, 2018

Codecov Report

Merging #906 into master will increase coverage by 0.05%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master     #906      +/-   ##
==========================================
+ Coverage   53.26%   53.32%   +0.05%     
==========================================
  Files         259      258       -1     
  Lines       16432    16374      -58     
==========================================
- Hits         8753     8731      -22     
+ Misses       7115     7079      -36     
  Partials      564      564

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but left some comments 😅

func TestHistoryContext_CreatedSince(t *testing.T) {
dateStr := "2009-11-10T23:00:00Z"
if runtime.GOOS == "windows" {
dateStr = "2009-11-11T00:00:00+01:00"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arf

Is this dependent on system configuration?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually not sure 😓 cc @simonferquel @johnstep

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems. the good thing is that the timezone is in the string here, and that the format is in a standard parsable from the time package. Comparison should be done after date/time parsing instead that on strings would be better though (and would not require windows specific code).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're testing a formatter, which is responsible for formatting output that is seen by a user, I think we should be comparing the string, not a time.Time. The format is relevant here.

{
args: []string{"plugin-foo", "nonexistent_context_dir"},
expectedError: "no such file or directory",
expectedError: noSuchFile,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is an os.IsNotFound() or os.IsFileNotFound function that would be prettier

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! you're right, was thinking about Linux CLI calling a Windows daemon (in which errors don't match), but that's not the case here

)

func TestRunBuildResetsUidAndGidInContext(t *testing.T) {
skip.IfCondition(t, runtime.GOOS == "windows", "uid and gid not relevant on windows")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this file already skipped on Windows?

Some of them are skipped for now (because the feature is not supported
or needs more work), some of them are fixed.

Signed-off-by: Vincent Demeester <[email protected]>
@vdemeester vdemeester force-pushed the fix-some-windows-unit-tests branch from f7f4172 to 8da068f Compare February 27, 2018 17:03
@@ -0,0 +1,54 @@
//+build linux
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use skip instead of the build directive? Or does this not build at all on windows?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dnephin it doesn't build at all on windows — there was a skip before 😓

}

func TestLoadKeyFromPath(t *testing.T) {
skip.If(t, func() bool { return runtime.GOOS == "windows" })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of the func() bool here you can use IfCondition, or update gotestyourself to 1.3.0 so that If accepts the bool.

Maybe add a reason why as well?

{Source: "/opt/data", Target: "/var/lib/mysql", Type: "bind"},
{Source: workingDir, Target: "/code", Type: "bind"},
{Source: workingDir + "/static", Target: "/var/www/html", Type: "bind"},
{Source: filepath.Join(workingDir, "/static"), Target: "/var/www/html", Type: "bind"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the / from /static ? Also on opt below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes the / is weird

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oups, I forgot to remove that one 🤦‍♂️

func TestHistoryContext_CreatedSince(t *testing.T) {
dateStr := "2009-11-10T23:00:00Z"
if runtime.GOOS == "windows" {
dateStr = "2009-11-11T00:00:00+01:00"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems. the good thing is that the timezone is in the string here, and that the format is in a standard parsable from the time package. Comparison should be done after date/time parsing instead that on strings would be better though (and would not require windows specific code).

)

func TestRunBuildResetsUidAndGidInContext(t *testing.T) {
dest := fs.NewDir(t, "test-build-context-dest")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should'nt we run this test on Darwin as well ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simonferquel yes, this is also on my TODO (but I should open an issue to track the work on that)

{
args: []string{"plugin-foo", "nonexistent_context_dir"},
expectedError: "no such file or directory",
expectedError: noSuchFile,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is an os.IsNotFound() or os.IsFileNotFound function that would be prettier

expectedMsg: "Unexpected",
},
{
// FIXME(vdemeester) that doesn't work under windows, the check needs to be smarter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the info endpoint could be queried instead of making the assumption that daemon os/platform == client os/platform

{Source: "/opt/data", Target: "/var/lib/mysql", Type: "bind"},
{Source: workingDir, Target: "/code", Type: "bind"},
{Source: workingDir + "/static", Target: "/var/www/html", Type: "bind"},
{Source: filepath.Join(workingDir, "/static"), Target: "/var/www/html", Type: "bind"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes the / is weird

{Source: homeDir + "/configs", Target: "/etc/configs/", Type: "bind", ReadOnly: true},
{Source: "datavolume", Target: "/var/lib/mysql", Type: "volume"},
{Source: workingDir + "/opt", Target: "/opt", Consistency: "cached", Type: "bind"},
{Source: filepath.Join(workingDir, "/opt"), Target: "/opt", Consistency: "cached", Type: "bind"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️

@vdemeester
Copy link
Collaborator Author

Closing this one as I'm putting the commit in #905 (and I'll take comments into account there)

@vdemeester vdemeester closed this Feb 28, 2018
@vdemeester vdemeester deleted the fix-some-windows-unit-tests branch June 26, 2018 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants