On Jun 6, 2009, at 8:40 AM, joel r wrote:

>
> On Tue, Jun 2, 2009 at 8:15 PM, Luke Kanies<[email protected]> wrote:
>>
>> Can you provide some comments in here on what these helpers are used
>> for?  It's a lot of scaffolding code, and it'd be nice if we could
>> find a way for it not to be necessary, because it makes the tests
>> harder to read in place.
>
> Well there are are a few things that get done at the beginning and end
> of each integration test, such as deleting users created by a test,
> creating users for a test, etc. It's these tasks that have gone into
> the scaffolding code. I've reduced it by quite a bit, and I've renamed
> some of the method names to make them more self explanatory. See my
> new code below. I'd appreciate your perspective. If you think they
> still need comments, I'll add them in. I really like to keep comments
> out of my code as far as possible though.

Does it make sense to split these tests between unit and integration  
tests, where the integration tests need this additional scaffolding  
but the unit tests don't, because they don't actually create real users?

I've had bad experiences with unit tests actually modifying the  
system; using stubs to avoid that, at least in the unit tests, has  
really paid off.

Of course, you still need to test that your system modifications work,  
but having those explicitly in the integration directory makes it  
clearer, so you can be sure the unit tests won't modify the real system.

I don't mean to be adding ridiculous burdens to getting the tests  
accepted, and I'm flexible on all of this, I'm just looking for  
guidance because I know so little of how the Windows side works.

>
> diff --git a/spec/lib/windowstest.rb b/spec/lib/windowstest.rb
> new file mode 100644
> index 0000000..d160fda
> --- /dev/null
> +++ b/spec/lib/windowstest.rb
> @@ -0,0 +1,60 @@
> +require File.dirname(__FILE__) + '/../../lib/puppet/util/ 
> windows_system.rb'
> +
> +module WindowsTest
> +    include Puppet::Util::Windows
> +
> +    def group(name)
> +        Group.new(name)
> +    end
> +
> +    def user(name)
> +        User.new(name)
> +    end
> +
> +    def create_test_groups(groupnames)
> +        list = groupnames.collect do |name|
> +            group = Puppet::Util::Windows::Group.create(name)
> +            delete_group_later name
> +            group
> +        end
> +
> +        return list[0] if list.length == 1
> +        return list
> +    end
> +
> +    def create_test_user(username, password)
> +        user = Puppet::Util::Windows::User.create(username, password)
> +        @users_to_delete << username
> +        return user
> +    end
> +
> +    def create_test_users(*usernames)
> +        password = "qwertyuiop"
> +
> +        list = usernames.flatten.collect do |name|
> +            create_test_user(name, password)
> +        end
> +
> +        return list[0] if list.length == 1
> +        return list
> +    end
> +
> +    def delete_test_users
> +        @users_to_delete.each {|name|
> Puppet::Util::Windows::User.delete(name) }
> +        @users_to_delete = []
> +    end
> +
> +    def delete_test_groups
> +        @groups_to_delete.each {|name|
> Puppet::Util::Windows::Group.delete(name) }
> +        @groups_to_delete = []
> +    end
> +
> +    def delete_group_later(groupname)
> +        @groups_to_delete << groupname
> +    end
> +
> +    def delete_user_later(username)
> +        @users_to_delete << username
> +    end
> +end
>
> >


-- 
When a man sits with a pretty girl for an hour, it seems like a
minute. But let him sit on a hot stove for a minute, and it's longer
than any hour. That's relativity. --Albert Einstein
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to