Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add validate_test.go to do unit test #188

Merged
merged 1 commit into from
Oct 18, 2016

Conversation

liangchenye
Copy link
Member

Only add a test case on checkSemVer in this PR.
Signed-off-by: liang chenye [email protected]

@wking
Copy link
Contributor

wking commented Aug 9, 2016

On Tue, Aug 09, 2016 at 04:17:40AM -0700, 梁辰晔 (Liang Chenye) wrote:

-- File Changes --

A cmd/ocitools/validate_test.go (27)

You probably want to add a Makefile and/or .travis.yml entry to run
these tests from Travis.

for _, c := range cases {
spec.Version = c.v
msg := checkSemVer(spec, "", false)
if len(msg) != c.expected {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is “number of error messages” really what we want to be checking here? I'd rather have a bunch of potential version strings with true/false for whether we thought they were valid, and error if we thought a version was valid and checkSemVer gave us error messages at all (logging the error messages with t.Fatalf) or if we thought a version was invalid and checkSemVer did not give us error messages.

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right, it is not necessary to check the number of error messages.

@wking
Copy link
Contributor

wking commented Aug 9, 2016

On Tue, Aug 09, 2016 at 04:17:40AM -0700, 梁辰晔 (Liang Chenye) wrote:

A cmd/ocitools/validate_test.go (27)

While I'm in favor of Go tests for our implementation, I'm not sure
it's worth testing cmd/… helpers. I'd rather see the validation code
pulled out into a Go library (like generate/…) and test that. Then
the cmd/… stuff should be a thin wrapper around that API, the API is
tested with ‘go test’ like you have here, and the command-line wrapper
is tested with sharness like I've floated in #180.

We'll also want a way to distinguish between “that's not valid” errors
[1](which are like HTTP 400s) and “that may be valid, but we can't
check it yet” errors [2](which are like HTTP 500s). My preferred
approach for that is to use Python's unittest and skip which lets you
handle generic JSON easily (vs. the current Go based on the
runtime-spec types or a hypothetical Go framework based on
interface{}). More on that in #98.

@liangchenye
Copy link
Member Author

I think it is a good idea to move 'validate' to a new directory like 'generate', I'll make a patch to move that.

(just back from a long time leaving)

@liangchenye
Copy link
Member Author

commit 82d0b38 moves validate directory out of cmd directory and add a 'validator' struct just like 'generator'.

commit 8b7ba22 adds a new unit test style based on Wking's comment

@wking @mrunalp PTAL

expected bool
}{
{rspec.Version, true},
{"0.0.1", false},
Copy link
Contributor

@wking wking Sep 1, 2016

Choose a reason for hiding this comment

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

0.0.1 looks like valid SemVer to me. What's the error message?

Copy link

Choose a reason for hiding this comment

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

Currently only support rspec.Version.

if version != rspec.Version {
        msgs = append(msgs, fmt.Sprintf("internal error: validate currently only handles version %s, but the supplied configuration targets %s", rspec.Version, version))
    }

Copy link
Contributor

Choose a reason for hiding this comment

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

On Mon, Sep 05, 2016 at 03:38:57AM -0700, David Liang wrote:

  •   {"0.0.1", false},
    

Currently only support rspec.Version.

So maybe leave a comment on this line that we're confirming a
shortcoming of the current test suite with this entry.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, I added a 'FIXME' to mention this.

type Validator struct {
spec rspec.Spec
rootfs string
hostSpecific bool
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather make these properties public, and Generator.HostSpecific is public. Do you have any reason to keep any of them private?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we need to see and modify these? I think the 'Check*' functions are enough.

Copy link
Contributor

Choose a reason for hiding this comment

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

On Wed, Sep 07, 2016 at 09:04:44PM -0700, 梁辰晔 (Liang Chenye) wrote:

+type Validator struct {

  • spec rspec.Spec
  • rootfs string
  • hostSpecific bool

Do we need to see and modify these? I think the 'Check*' functions
are enough.

Making them public means you don't need getters/setters and you can
still support users who want to partially setup the instance when they
call NewValidator (or whatever 1) and finish the setup later. Or if
they want to peer inside to get more details on why their validation
is failing. Or who knows? I'd rather err on the side of “we're all
consenting adults” 2, because I don't see a way to make validation
go terribly wrong if a user gets or sets one of these values whenever
they like.

Copy link
Contributor

@wking wking Sep 8, 2016 via email

Choose a reason for hiding this comment

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

@liangchenye
Copy link
Member Author

Hi @wking , I modified codes according to your suggestion.
Just one difference: using RootfsPath other than BundlePath in Validator{} .

return Validator{}, fmt.Errorf("Cannot find the root path %q", rootfsPath)
} else if !fi.IsDir() {
return Validator{}, fmt.Errorf("The root path %q is not a directory.", rootfsPath)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This “does the rootfs exist” check should be a separate check in Validator.CheckAll()

Copy link
Member Author

Choose a reason for hiding this comment

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

done in new commit!

@liangchenye
Copy link
Member Author

Rebase by using 'runtime-tools'.
Merge two commits (one for restruct and one for unit test case) into one. The original change log can not reflect the real meaning, code changes a lot after discussions with @wking.

@mrunalp PTAL

return Validator{spec: spec, bundlePath: bundlePath, HostSpecific: hostSpecific}
}

func NewValidatorFromPath(bundlePath string, hostSpecific bool) (Validator, error) {
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 these NewValidator* functions should return (*Validator, error).

@wking
Copy link
Contributor

wking commented Sep 19, 2016 via email

@liangchenye
Copy link
Member Author

Travis fails because of:
#230

@liangchenye
Copy link
Member Author

#7cd3aa1 rebased on top of current 'master'.
Only difference with '#a8c02cf ' is '7cd3aa1' includes Mashimiao's new patch:
'validate: add hard and soft limit check for rlimit'
e129a67

@Mashimiao @mrunalp PTAL

@vbatts
Copy link
Member

vbatts commented Oct 6, 2016

so the test fail is due to go1.5?

@liangchenye
Copy link
Member Author

@vbatts yes, I'll rebuild the CI.

The command "go get github.com/golang/lint/golint" failed and exited with 2 during

@liangchenye
Copy link
Member Author

@mrunalp @Mashimiao rebased.
Merge new IsAbs and const 'config.json' changes.

It is a code struct change, please PTAL first :)

@Mashimiao
Copy link

bde9989 looks good to me

@mrunalp
Copy link
Contributor

mrunalp commented Oct 18, 2016

LGTM

@mrunalp mrunalp merged commit 7ff34fc into opencontainers:master Oct 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants