Skip to content

Commit

Permalink
updating tests and adding license headers
Browse files Browse the repository at this point in the history
  • Loading branch information
saniales committed Aug 22, 2017
1 parent 262afd9 commit 426089f
Show file tree
Hide file tree
Showing 10 changed files with 300 additions and 20 deletions.
28 changes: 15 additions & 13 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,21 @@
* Copyright 2017 BCMI LABS SA (http://www.arduino.cc/)
*/

// Package auth uses the `oauth2 authorization_code` flow to authenticate with Arduino
//
// If you have the username and password of a user, you can just instantiate a client with sane defaults:
//
// client := auth.New()
//
// and then call the Token method to obtain a Token object with an AccessToken and a RefreshToken
//
// token, err := client.Token(username, password)
//
// If instead you already have a token but want to refresh it, just call
//
// token, err := client.refresh(refreshToken)
/*
Package auth uses the `oauth2 authorization_code` flow to authenticate with Arduino
If you have the username and password of a user, you can just instantiate a client with sane defaults:
client := auth.New()
and then call the Token method to obtain a Token object with an AccessToken and a RefreshToken
token, err := client.Token(username, password)
If instead you already have a token but want to refresh it, just call
token, err := client.refresh(refreshToken)
*/
package auth

import (
Expand Down
29 changes: 29 additions & 0 deletions cmd/cmd_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
/*
* This file is part of arduino-cli.
*
* arduino-cli is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2017 BCMI LABS SA (http://www.arduino.cc/)
*/

package cmd_test

import (
Expand Down
29 changes: 29 additions & 0 deletions cmd/formatter/examples_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
/*
* This file is part of arduino-cli.
*
* arduino-cli is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2017 BCMI LABS SA (http://www.arduino.cc/)
*/

package formatter_test

import (
Expand Down
29 changes: 29 additions & 0 deletions cmd/formatter/print_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
/*
* This file is part of arduino-cli.
*
* arduino-cli is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2017 BCMI LABS SA (http://www.arduino.cc/)
*/

package formatter_test

import (
Expand Down
29 changes: 29 additions & 0 deletions cmd/manpages.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
/*
* This file is part of arduino-cli.
*
* arduino-cli is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2017 BCMI LABS SA (http://www.arduino.cc/)
*/

package cmd

import (
Expand Down
7 changes: 0 additions & 7 deletions cmd/output/interfaces.go

This file was deleted.

29 changes: 29 additions & 0 deletions common/releases/checksums.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
/*
* This file is part of arduino-cli.
*
* arduino-cli is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2017 BCMI LABS SA (http://www.arduino.cc/)
*/

package releases

import (
Expand Down
29 changes: 29 additions & 0 deletions cores/install_uninstall.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
/*
* This file is part of arduino-cli.
*
* arduino-cli is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2017 BCMI LABS SA (http://www.arduino.cc/)
*/

package cores

import (
Expand Down
29 changes: 29 additions & 0 deletions cores/tools.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
/*
* This file is part of arduino-cli.
*
* arduino-cli is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2017 BCMI LABS SA (http://www.arduino.cc/)
*/

package cores

import (
Expand Down
82 changes: 82 additions & 0 deletions task/examples_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package task_test

import (
"errors"
"fmt"

"github.com/bcmi-labs/arduino-cli/task"
)

func ExampleWrapper_Execute() {
i := 0

taskToAccomplish := func() task.Result {
var ret task.Result
i++
// if I call this function an odd number of times it triggers an error.
if i%2 == 0 {
ret.Error = errors.New("I am triggering an error: I hate odd numbers!!!")
}
// if I call this function an even and multiple of 3 number of times it triggers a result.
if i%3 == 0 && i%2 != 0 {
ret.Result = "Triggering a result, I love even multiples of 3 and I want to let you know it"
}
fmt.Println("I am printing something on the console")
return ret
}

exampleTask := task.Wrapper{
BeforeMessage: []string{
"doing something",
"doing something talking a lot",
"doing something talking a lot and explaining step by step what I am doing, really",
},
AfterMessage: []string{
"Done",
"I finished",
"I accomplished my job in a very accurate way, and without errors",
},
ErrorMessage: []string{
"error happened",
"I got an error during the execution of the function",
"I got an error during the execution of the function, which blocked me to continue my job, making me sad",
},
Task: taskToAccomplish,
}

//crescent level of verbosity.
for i := 0; i < 5; i++ {
result := exampleTask.Execute(i)
if result.Result != nil {
fmt.Println("RESULT: ", result.Result)
}
if result.Error != nil {
fmt.Println("ERROR: ", result.Error)
}
fmt.Println()
}

// Output:
// doing something ...
// I am printing something on the console
// Done
//
// doing something talking a lot ...
// I am printing something on the console
// I got an error during the execution of the function
// ERROR: I am triggering an error: I hate odd numbers!!!
//
// doing something talking a lot and explaining step by step what I am doing, really ...
// I am printing something on the console
// I accomplished my job in a very accurate way, and without errors
// RESULT: Triggering a result, I love even multiples of 3 and I want to let you know it
//
// doing something talking a lot and explaining step by step what I am doing, really ...
// I am printing something on the console
// I got an error during the execution of the function, which blocked me to continue my job, making me sad
// ERROR: I am triggering an error: I hate odd numbers!!!
//
// doing something talking a lot and explaining step by step what I am doing, really ...
// I am printing something on the console
// I accomplished my job in a very accurate way, and without errors
}

0 comments on commit 426089f

Please sign in to comment.