Skip to content
This repository has been archived by the owner on Apr 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #66 from KSP-CKAN/fix/staging
Browse files Browse the repository at this point in the history
Fix NetKAN staging
  • Loading branch information
techman83 committed Aug 16, 2018
2 parents 3a659d7 + 714e546 commit 75e4c35
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
10 changes: 5 additions & 5 deletions lib/App/KSP_CKAN/Metadata/NetKAN.pm
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,20 @@ method _build_license {
}

method _build_staging {
return $self->_raw->{config}{'x-netkan-staging'} ? $self->_raw->{config}{'x-netkan-staging'} : 0 ;
return $self->_raw->{config}{'x_netkan_staging'} ? $self->_raw->{config}{'x_netkan_staging'} : 0 ;
}

=method licenses
$ckan->licenses();
Returns the license field as an array. Because unless there is
multiple values it won't be.
=cut
# Sometimes we always want an array.
method licenses {

# Sometimes we always want an array.
method licenses {
my @licenses = reftype \$self->license ne "SCALAR" ? @{$self->license} : $self->license;
return \@licenses;
}
Expand Down
32 changes: 16 additions & 16 deletions t/App/KSP_CKAN/Tools/Git.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ subtest 'Working Dir Parsing' => sub {
'git@github.com:techman83/CKAN-meta.git',
'https://github.com/techman83/CKAN-meta.git',
);

foreach my $working (@test_git) {
my $git = App::KSP_CKAN::Tools::Git->new(
remote => $working,
local => $test->tmp,
);
is($git->working, 'CKAN-meta', "'CKAN-meta' parsed from $working");

is($git->working, 'CKAN-meta', "'CKAN-meta' parsed from $working");
};
};

Expand Down Expand Up @@ -64,7 +64,7 @@ subtest 'Committing' => sub {
is($git->changed, 1, "Commit not yet pushed");
$git->push;
is($git->changed, 0, "Commit pushed");

# Test committing all files
for my $filename (qw(test_file2.ckan test_file3.ckan)) {
$test->create_ckan( file => $test->tmp."/CKAN-meta/".$filename );
Expand Down Expand Up @@ -104,7 +104,7 @@ is(-e $test->tmp."/CKAN-meta/test_pull.ckan", 1, "Pull successful");
# Test accidental deletes
unlink($test->tmp."/CKAN-meta/test_file.ckan");
$git->add;
is($git->changed, 2, "File delete not commited");
is($git->changed, 2, "File delete not committed");

# Test cleanup
$test->create_ckan( file => $test->tmp."/CKAN-meta/cleaned_file.ckan" );
Expand Down Expand Up @@ -139,7 +139,7 @@ subtest 'Git Errors' => sub {
subtest 'Staged Commit' => sub {
my $file = $test->tmp."/CKAN-meta/staged.ckan";
my $identifier = "Testing";

# Initial File Creation
$test->create_ckan( file => $file );
$git->add($file);
Expand All @@ -149,21 +149,21 @@ subtest 'Staged Commit' => sub {
identifier => $identifier,
message => "New File",
);
is($success, 1, "We commited a new file to staging");
is($success, 1, "We committed a new file to staging");
$git->_hard_clean;

is($git->current_branch, "master", "We returned to the master branch");
isnt(-e $file, 1, "Our staged file wasn't commited to master");
isnt(-e $file, 1, "Our staged file wasn't committed to master");

$git->checkout_branch("staging");
is($git->current_branch, "staging", "We are on to the staging branch");
$git->_hard_clean;
is(digest_file_hex( $file, "SHA-1" ), $hash, "Our staging branch was commited to");
is(digest_file_hex( $file, "SHA-1" ), $hash, "Our staging branch was committed to");
$git->checkout_branch($identifier);
is($git->current_branch, $identifier, "We are on the $identifier branch");
$git->_hard_clean;
is(digest_file_hex( $file, "SHA-1" ), $hash, "Our $identifier branch was commited to");
is(digest_file_hex( $file, "SHA-1" ), $hash, "Our $identifier branch was committed to");

# File update
$test->create_ckan( file => $file, random => 0 );
$hash = digest_file_hex( $file, "SHA-1" );
Expand All @@ -174,13 +174,13 @@ subtest 'Staged Commit' => sub {
message => "Modified File",
);
$git->_hard_clean;
is($update, 1, "We commited a change to staging");
# Get the last commit ID from staging
is($update, 1, "We committed a change to staging");

# Get the last commit ID from staging
$git->checkout_branch("staging");
my $commit = $git->last_commit;
$git->checkout_branch("master");

# Update with no changes
$test->create_ckan( file => $file, random => 0 );
$git->add($file);
Expand Down
2 changes: 1 addition & 1 deletion t/data/NetKAN/NetKAN/DogeCoinFlagStaged.netkan
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
"resources" : {
"homepage" : "https://www.reddit.com/r/dogecoin/comments/1tdlgg/i_made_a_more_accurate_dogecoin_and_a_ksp_flag/"
},
"x-netkan-staging" : 1
"x_netkan_staging" : 1
}
38 changes: 19 additions & 19 deletions t/lib/App/KSP_CKAN/Test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ method _random_string {
$test->create_tmp;
This will deploy our temp environment. Only required if we
This will deploy our temp environment. Only required if we
aren't creating a repo (one will be built on demand).
=cut
Expand All @@ -80,7 +80,7 @@ Turns the named repo into a working local remote.

method create_repo($repo) {
local $CWD = $self->_tmp."/data/$repo";
capture { system("git", "init") };
capture { system("git", "init") };
capture { system("git", "add", "-A") };
capture { system("git", "commit", "-a", "-m", "Commit ALL THE THINGS!") };
chdir("../");
Expand All @@ -90,15 +90,15 @@ method create_repo($repo) {
}

=method create_ckan
$test->create_ckan(file => "/path/to/file");
Creates an example ckan that would pass validation at the specified
path.
Takes an optional extra argument, that if set to false will create
a ckan that won't pass schema validation.
$test->create_ckan( file => "/path/to/file", valid => 0);
=over
Expand All @@ -114,7 +114,7 @@ validation against the schema.
=item kind
Allows us to specify a different kind of package. 'metadata' is the
Allows us to specify a different kind of package. 'metadata' is the
only accepted one at the moment.
=item license
Expand All @@ -126,10 +126,10 @@ Allows us to specify a different license.
=cut

method create_ckan(
:$file,
:$valid = 1,
:$random = 1,
:$identifier = "ExampleKAN",
:$file,
:$valid = 1,
:$random = 1,
:$identifier = "ExampleKAN",
:$kind = "package",
:$license = '"CC-BY-NC-SA"',
:$download = "https://example.com/example.zip",
Expand Down Expand Up @@ -157,25 +157,25 @@ method create_ckan(
}

=method cleanup
$test->cleanup;
Does what it says on the tin, cleans up our mess.
=cut

=method create_config
$test->create_config( optional => 0 );
Creates a dummy config file for testing. The 'optional'
defaults to true if unspecified, generating a test config
defaults to true if unspecified, generating a test config
with optional values.
=cut

=method create_netkan
$test->create_netkan(file => "/path/to/file");
Creates an example netkan that would pass validation at the specified
Expand Down Expand Up @@ -204,15 +204,15 @@ Allows us to specify a different or undef vref.
=cut

method create_netkan(
:$file,
:$identifier = "DogeCoinFlag",
:$file,
:$identifier = "DogeCoinFlag",
:$kref = "#/ckan/github/pjf/DogeCoinFlag",
:$vref = "#/ckan/ksp-avc",
:$staging = 0,
:$random = 1,
:$random = 1,
) {
my $vref_field = $vref ? qq|"\$vref" : "$vref",| : "";
my $staging_field = $vref ? "" : qq|,"x-netkan-staging" : 1|;
my $staging_field = $vref ? "" : qq|,"x_netkan_staging" : 1|;
my $rand = $random ? $self->_random_string : "random";

# Create the NetKAN
Expand All @@ -231,7 +231,7 @@ method create_config(:$optional = 1, :$nogh = 0) {
print $in "ckan_schema=https://raw.githubusercontent.com/KSP-CKAN/CKAN/master/CKAN.schema\n";
print $in "IA_access=12345678\n";
print $in "IA_secret=87654321\n";

# TODO: This is a little ugly.
if ($optional) {
print $in "GH_token=123456789\n" if ! $nogh;
Expand All @@ -245,7 +245,7 @@ method create_config(:$optional = 1, :$nogh = 0) {
}

=method cleanup
$test->cleanup;
Does what it says on the tin, cleans up our mess.
Expand Down

0 comments on commit 75e4c35

Please sign in to comment.