pax_global_header00006660000000000000000000000064142706310240014511gustar00rootroot0000000000000052 comment=661e16e3650bbe268c2f74fa1a9d4cabaed2e355 version-2.0.1/000077500000000000000000000000001427063102400131765ustar00rootroot00000000000000version-2.0.1/.gitignore000066400000000000000000000004121427063102400151630ustar00rootroot00000000000000# Compiled Object files, Static and Dynamic libs (Shared Objects) *.o *.a *.so # Folders _obj _test # Architecture specific extensions/prefixes *.[568vq] [568vq].out *.cgo1.go *.cgo2.c _cgo_defun.c _cgo_gotypes.go _cgo_export.* _testmain.go *.exe *.test *.prof version-2.0.1/LICENSE000066400000000000000000000215021427063102400142030ustar00rootroot00000000000000All files in this repository are licensed as follows. If you contribute to this repository, it is assumed that you license your contribution under the same license unless you state otherwise. All files Copyright (C) 2015 Canonical Ltd. unless otherwise specified in the file. This software is licensed under the LGPLv3, included below. As a special exception to the GNU Lesser General Public License version 3 ("LGPL3"), the copyright holders of this Library give you permission to convey to a third party a Combined Work that links statically or dynamically to this Library without providing any Minimal Corresponding Source or Minimal Application Code as set out in 4d or providing the installation information set out in section 4e, provided that you comply with the other provisions of LGPL3 and provided that you meet, for the Application the terms and conditions of the license(s) which apply to the Application. Except as stated in this special exception, the provisions of LGPL3 will continue to comply in full to this Library. If you modify this Library, you may apply this exception to your version of this Library, but you are not obliged to do so. If you do not wish to do so, delete this exception statement from your version. This exception does not (and cannot) modify any license terms which apply to the Application, with which you must still comply. GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. version-2.0.1/README.md000066400000000000000000000002651427063102400144600ustar00rootroot00000000000000# Version [![GoDoc](https://godoc.org/github.com/juju/version?status.svg)](https://godoc.org/github.com/juju/version) version is a go package for intelligent version comparisons. version-2.0.1/go.mod000066400000000000000000000007021427063102400143030ustar00rootroot00000000000000module github.com/juju/version/v2 go 1.17 require ( github.com/juju/mgo/v3 v3.0.2 github.com/juju/testing v1.0.1 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b ) require ( github.com/juju/loggo v1.0.0 // indirect github.com/kr/pretty v0.3.0 // indirect github.com/kr/text v0.2.0 // indirect github.com/rogpeppe/go-internal v1.8.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) version-2.0.1/go.sum000066400000000000000000000413061427063102400143350ustar00rootroot00000000000000github.com/Azure/go-ntlmssp v0.0.0-20211209120228-48547f28849e/go.mod h1:chxPXzSsl7ZWRAuOIE23GDNzjWuZquvFlgA8xmpunjU= github.com/ChrisTrenkamp/goxpath v0.0.0-20210404020558-97928f7e12b6/go.mod h1:nuWgzSkT5PnyOd+272uUmV0dnAnAn42Mk7PiQC5VzN4= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs= github.com/jcmturner/dnsutils/v2 v2.0.0/go.mod h1:b0TnjGOvI/n42bZa+hmXL+kFJZsFT7G4t3HTlQ184QM= github.com/jcmturner/gofork v1.0.0/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o= github.com/jcmturner/goidentity/v6 v6.0.1/go.mod h1:X1YW3bgtvwAXju7V3LCIMpY0Gbxyjn/mY9zx4tFonSg= github.com/jcmturner/gokrb5/v8 v8.4.2/go.mod h1:sb+Xq/fTY5yktf/VxLsE3wlfPqQjp0aWNYyvBVK62bc= github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc= github.com/juju/ansiterm v0.0.0-20160907234532-b99631de12cf/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU= github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU= github.com/juju/ansiterm v0.0.0-20210706145210-9283cdf370b5/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU= github.com/juju/clock v0.0.0-20190205081909-9c5c9712527c/go.mod h1:nD0vlnrUjcjJhqN5WuCWZyzfd5AHZAC9/ajvbSx69xA= github.com/juju/clock v0.0.0-20220202072423-1b0f830854c4/go.mod h1:zDZCPSgCJQINeZtQwHx2/cFk4seaBC8Yiqe8V82xiP0= github.com/juju/clock v0.0.0-20220203021603-d9deb868a28a/go.mod h1:GZ/FY8Cqw3KHG6DwRVPUKbSPTAwyrU28xFi5cqZnLsc= github.com/juju/clock v1.0.0/go.mod h1:GZ/FY8Cqw3KHG6DwRVPUKbSPTAwyrU28xFi5cqZnLsc= github.com/juju/cmd v0.0.0-20171107070456-e74f39857ca0/go.mod h1:yWJQHl73rdSX4DHVKGqkAip+huBslxRwS8m9CrOLq18= github.com/juju/cmd/v3 v3.0.0-20220202061353-b1cc80b193b0/go.mod h1:EoGJiEG+vbMwO9l+Es0SDTlaQPjH6nLcnnc4NfZB3cY= github.com/juju/collections v0.0.0-20200605021417-0d0ec82b7271/go.mod h1:5XgO71dV1JClcOJE+4dzdn4HrI5LiyKd7PlVG6eZYhY= github.com/juju/collections v0.0.0-20220203020748-febd7cad8a7a/go.mod h1:JWeZdyttIEbkR51z2S13+J+aCuHVe0F6meRy+P0YGDo= github.com/juju/collections v1.0.0/go.mod h1:JWeZdyttIEbkR51z2S13+J+aCuHVe0F6meRy+P0YGDo= github.com/juju/errors v0.0.0-20150916125642-1b5e39b83d18/go.mod h1:W54LbzXuIE0boCoNJfwqpmkKJ1O4TCTZMetAt6jGk7Q= github.com/juju/errors v0.0.0-20200330140219-3fe23663418f/go.mod h1:W54LbzXuIE0boCoNJfwqpmkKJ1O4TCTZMetAt6jGk7Q= github.com/juju/errors v0.0.0-20210818161939-5560c4c073ff/go.mod h1:i1eL7XREII6aHpQ2gApI/v6FkVUDEBremNkcBCKYAcY= github.com/juju/errors v0.0.0-20220203013757-bd733f3c86b9/go.mod h1:TRm7EVGA3mQOqSVcBySRY7a9Y1/gyVhh/WTCnc5sD4U= github.com/juju/errors v1.0.0/go.mod h1:B5x9thDqx0wIMH3+aLIMP9HjItInYWObRovoCFM5Qe8= github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE= github.com/juju/httpprof v0.0.0-20141217160036-14bf14c30767/go.mod h1:+MaLYz4PumRkkyHYeXJ2G5g5cIW0sli2bOfpmbaMV/g= github.com/juju/loggo v0.0.0-20170605014607-8232ab8918d9/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U= github.com/juju/loggo v0.0.0-20200526014432-9ce3a2e09b5e/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U= github.com/juju/loggo v0.0.0-20210728185423-eebad3a902c4/go.mod h1:NIXFioti1SmKAlKNuUwbMenNdef59IF52+ZzuOmHYkg= github.com/juju/loggo v1.0.0 h1:Y6ZMQOGR9Aj3BGkiWx7HBbIx6zNwNkxhVNOHU2i1bl0= github.com/juju/loggo v1.0.0/go.mod h1:NIXFioti1SmKAlKNuUwbMenNdef59IF52+ZzuOmHYkg= github.com/juju/mgo/v2 v2.0.0-20210302023703-70d5d206e208/go.mod h1:0OChplkvPTZ174D2FYZXg4IB9hbEwyHkD+zT+/eK+Fg= github.com/juju/mgo/v2 v2.0.0-20220111072304-f200228f1090/go.mod h1:N614SE0a4e+ih2rg96Vi2PeC3cTpUOWgCTv3Cgk974c= github.com/juju/mgo/v3 v3.0.2 h1:I2F9bfxhlydulZhtTSYm+r0k6T3SDkgs4oJZ3TCTnTY= github.com/juju/mgo/v3 v3.0.2/go.mod h1:fAvhDCRbUlEbRIae6UQT8RvPUoLwKnJsBgO6OzHKNxw= github.com/juju/mutex v0.0.0-20171110020013-1fe2a4bf0a3a/go.mod h1:Y3oOzHH8CQ0Ppt0oCKJ2JFO81/EsWenH5AEqigLH+yY= github.com/juju/mutex/v2 v2.0.0-20220128011612-57176ebdcfa3/go.mod h1:TTCG9BJD9rCC4DZFz3jA0QvCqFDHw8Eqz0jstwY7RTQ= github.com/juju/mutex/v2 v2.0.0-20220203023141-11eeddb42c6c/go.mod h1:jwCfBs/smYDaeZLqeaCi8CB8M+tOes4yf827HoOEoqk= github.com/juju/retry v0.0.0-20151029024821-62c620325291/go.mod h1:OohPQGsr4pnxwD5YljhQ+TZnuVRYpa5irjugL1Yuif4= github.com/juju/retry v0.0.0-20180821225755-9058e192b216/go.mod h1:OohPQGsr4pnxwD5YljhQ+TZnuVRYpa5irjugL1Yuif4= github.com/juju/retry v1.0.0/go.mod h1:SssN1eYeK3A2qjnFGTiVMbdzGJ2BfluaJblJXvuvgqA= github.com/juju/testing v0.0.0-20180402130637-44801989f0f7/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA= github.com/juju/testing v0.0.0-20180517134105-72703b1e95eb/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA= github.com/juju/testing v0.0.0-20190723135506-ce30eb24acd2/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA= github.com/juju/testing v0.0.0-20210302031854-2c7ee8570c07/go.mod h1:7lxZW0B50+xdGFkvhAb8bwAGt6IU87JB1H9w4t8MNVM= github.com/juju/testing v0.0.0-20210324180055-18c50b0c2098/go.mod h1:7lxZW0B50+xdGFkvhAb8bwAGt6IU87JB1H9w4t8MNVM= github.com/juju/testing v0.0.0-20220202055744-1ad0816210a6/go.mod h1:QgWc2UdIPJ8t3rnvv95tFNOsQDfpXYEZDbP281o3b2c= github.com/juju/testing v0.0.0-20220203020004-a0ff61f03494/go.mod h1:rUquetT0ALL48LHZhyRGvjjBH8xZaZ8dFClulKK5wK4= github.com/juju/testing v1.0.0/go.mod h1:rUquetT0ALL48LHZhyRGvjjBH8xZaZ8dFClulKK5wK4= github.com/juju/testing v1.0.1 h1:Zlg3HKP+wBRpkxCmh+Bsxp3WOmfelcZXuX6Adb7Dvec= github.com/juju/testing v1.0.1/go.mod h1:h3Vd2rzB57KrdsBEy6R7bmSKPzP76BnNavt7i8PerwQ= github.com/juju/utils v0.0.0-20180424094159-2000ea4ff043/go.mod h1:6/KLg8Wz/y2KVGWEpkK9vMNGkOnu4k/cqs8Z1fKjTOk= github.com/juju/utils v0.0.0-20200116185830-d40c2fe10647/go.mod h1:6/KLg8Wz/y2KVGWEpkK9vMNGkOnu4k/cqs8Z1fKjTOk= github.com/juju/utils/v2 v2.0.0-20200923005554-4646bfea2ef1/go.mod h1:fdlDtQlzundleLLz/ggoYinEt/LmnrpNKcNTABQATNI= github.com/juju/utils/v3 v3.0.0-20220130232349-cd7ecef0e94a/go.mod h1:LzwbbEN7buYjySp4nqnti6c6olSqRXUk6RkbSUUP1n8= github.com/juju/utils/v3 v3.0.0-20220202114721-338bb0530e89/go.mod h1:wf5w+8jyTh2IYnSX0sHnMJo4ZPwwuiBWn+xN3DkQg4k= github.com/juju/utils/v3 v3.0.0-20220203023959-c3fbc78a33b0/go.mod h1:8csUcj1VRkfjNIRzBFWzLFCMLwLqsRWvkmhfVAUwbC4= github.com/juju/utils/v3 v3.0.0/go.mod h1:8csUcj1VRkfjNIRzBFWzLFCMLwLqsRWvkmhfVAUwbC4= github.com/juju/version v0.0.0-20161031051906-1f41e27e54f2/go.mod h1:kE8gK5X0CImdr7qpSKl3xB2PmpySSmfj7zVbkZFs81U= github.com/juju/version v0.0.0-20180108022336-b64dbd566305/go.mod h1:kE8gK5X0CImdr7qpSKl3xB2PmpySSmfj7zVbkZFs81U= github.com/juju/version v0.0.0-20191219164919-81c1be00b9a6 h1:nrqc9b4YKpKV4lPI3GPPFbo5FUuxkWxgZE2Z8O4lgaw= github.com/juju/version v0.0.0-20191219164919-81c1be00b9a6/go.mod h1:kE8gK5X0CImdr7qpSKl3xB2PmpySSmfj7zVbkZFs81U= github.com/juju/version/v2 v2.0.0-20211007103408-2e8da085dc23/go.mod h1:Ljlbryh9sYaUSGXucslAEDf0A2XUSGvDbHJgW8ps6nc= github.com/juju/version/v2 v2.0.0/go.mod h1:ZeFjNy+UFEWJDDPdzW7Cm9NeU6dsViGaFYhXzycLQrw= github.com/julienschmidt/httprouter v1.1.1-0.20151013225520-77a895ad01eb/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lunixbochs/vtclean v0.0.0-20160125035106-4fbf7632a2c6/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= github.com/masterzen/azure-sdk-for-go v3.2.0-beta.0.20161014135628-ee4f0065d00c+incompatible/go.mod h1:mf8fjOu33zCqxUjuiU3I8S1lJMyEAlH+0F2+M5xl3hE= github.com/masterzen/simplexml v0.0.0-20160608183007-4572e39b1ab9/go.mod h1:kCEbxUJlNDEBNbdQMkPSp6yaKcRXVI6f4ddk8Riv4bc= github.com/masterzen/simplexml v0.0.0-20190410153822-31eea3082786/go.mod h1:kCEbxUJlNDEBNbdQMkPSp6yaKcRXVI6f4ddk8Riv4bc= github.com/masterzen/winrm v0.0.0-20161014151040-7a535cd943fc/go.mod h1:CfZSN7zwz5gJiFhZJz49Uzk7mEBHIceWmbFmYx7Hf7E= github.com/masterzen/winrm v0.0.0-20211231115050-232efb40349e/go.mod h1:Iju3u6NzoTAvjuhsGCZc+7fReNnr/Bd6DsWj3WTokIU= github.com/masterzen/xmlpath v0.0.0-20140218185901-13f4951698ad/go.mod h1:A0zPC53iKKKcXYxr4ROjpQRQ5FgJXtelNdSmHHuq/tY= github.com/mattn/go-colorable v0.0.6/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.0-20160806122752-66b8e73f3f5c/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg= github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM= github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8= golang.org/x/crypto v0.0.0-20180214000028-650f4a345ab4/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201112155050-0c6587e931a9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180406214816-61147c48b25b/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200904194848-62affa334b73/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20160105164936-4f90aeace3a2/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v1 v1.0.0-20161222125816-442357a80af5/go.mod h1:u0ALmqvLRxLI95fkdCEWrE6mhWYZW1aMOJHp5YXLHTg= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/httprequest.v1 v1.1.1/go.mod h1:/CkavNL+g3qLOrpFHVrEx4NKepeqR4XTZWNj4sGGjz0= gopkg.in/mgo.v2 v2.0.0-20160818015218-f2b6f6c918c4/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637/go.mod h1:BHsqpu/nsuzkT5BpiH1EMZPLyqSMM8JbIavyFACoFNk= gopkg.in/yaml.v2 v2.0.0-20170712054546-1be3d31502d6/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM= launchpad.net/xmlpath v0.0.0-20130614043138-000000000004/go.mod h1:vqyExLOM3qBx7mvYRkoxjSCF945s0mbe7YynlKYXtsA= version-2.0.1/package_test.go000066400000000000000000000003201427063102400161520ustar00rootroot00000000000000// Copyright 2013 Canonical Ltd. // Licensed under the LGPLv3, see LICENCE file for details. package version_test import ( "testing" gc "gopkg.in/check.v1" ) func Test(t *testing.T) { gc.TestingT(t) } version-2.0.1/version.go000066400000000000000000000225331427063102400152170ustar00rootroot00000000000000// Copyright 2012, 2013 Canonical Ltd. // Licensed under the LGPLv3, see LICENCE file for details. // Package version implements version parsing. package version import ( "encoding/json" "errors" "fmt" "regexp" "strconv" "strings" "github.com/juju/mgo/v3/bson" ) // Number represents a version number. type Number struct { Major int Minor int Tag string Patch int Build int } // Zero is occasionally convenient and readable. // Please don't change its value. var Zero = Number{} // Binary specifies a binary version of juju.v type Binary struct { Number Release string Arch string } // String returns the string representation of the binary version. func (b Binary) String() string { return fmt.Sprintf("%v-%s-%s", b.Number, b.Release, b.Arch) } // GetBSON implements bson.Getter. func (b Binary) GetBSON() (interface{}, error) { return b.String(), nil } // SetBSON implements bson.Setter. func (b *Binary) SetBSON(raw bson.Raw) error { var s string err := raw.Unmarshal(&s) if err != nil { return err } v, err := ParseBinary(s) if err != nil { return err } *b = v return nil } // MarshalJSON implements json.Marshaler. func (b Binary) MarshalJSON() ([]byte, error) { return json.Marshal(b.String()) } // UnmarshalJSON implements json.Unmarshaler. func (b *Binary) UnmarshalJSON(data []byte) error { var s string if err := json.Unmarshal(data, &s); err != nil { return err } v, err := ParseBinary(s) if err != nil { return err } *b = v return nil } // MarshalYAML implements yaml.v2.Marshaller interface. func (b Binary) MarshalYAML() (interface{}, error) { return b.String(), nil } // UnmarshalYAML implements the yaml.Unmarshaller interface. func (b *Binary) UnmarshalYAML(unmarshal func(interface{}) error) error { var vstr string err := unmarshal(&vstr) if err != nil { return err } v, err := ParseBinary(vstr) if err != nil { return err } *b = v return nil } const ( // NumberRegex for matching version strings in the forms: // - 1.2 // - 1.2.3 // - 1.2.3.4 // - 1.2-alpha3 // - 1.2-alpha3.4 NumberRegex = `(?P\d{1,9})(\.((?P\d{1,9})((?:(-((?P[a-z]+)(?P\d{1,9})?))|(\.(?P\d{1,9})))?)(\.(?P\d{1,9}))?))?` // BinaryRegex for matching binary version strings in the form: // - 1.2-release-arch // - 1.2.3-release-arch // - 1.2.3.4-release-arch // - 1.2-alpha3-release-arch // - 1.2-alpha3.4-release-arch BinaryRegex = NumberRegex + `-(?P[^-]+)-(?P[^-]+)` ) var ( binaryPat = regexp.MustCompile(`^` + BinaryRegex + `$`) numberPat = regexp.MustCompile(`^` + NumberRegex + `$`) errInvalidVersion = errors.New("invalid version") ) // MustParse parses a version and panics if it does // not parse correctly. func MustParse(s string) Number { v, err := Parse(s) if err != nil { panic(err) } return v } // MustParseBinary parses a binary version and panics if it does // not parse correctly. func MustParseBinary(s string) Binary { b, err := ParseBinary(s) if err != nil { panic(err) } return b } // ParseBinary parses a binary version of the form "1.2.3-series-arch". func ParseBinary(s string) (Binary, error) { groups := captureNamedGroups(s, binaryPat) n := parseVersion(groups, true) if n == nil { return Binary{}, fmt.Errorf("invalid binary version %q", s) } return Binary{ Number: *n, Release: groups["release"], Arch: groups["arch"], }, nil } // Parse a version in strict mode. The following version patterns are accepted: // 1.2.3 (major, minor, patch) // 1.2-tag3 (major, minor, patch, tag) // 1.2.3.4 (major, minor, patch, build) // 1.2-tag3.4 (major, minor, patch, build) // // The ParseNonStrict function can be used instead to parse a wider range of // version patterns (e.g. major only, major/minor etc.). func Parse(s string) (Number, error) { groups := captureNamedGroups(s, numberPat) if n := parseVersion(groups, true); n != nil { return *n, nil } return Number{}, fmt.Errorf("invalid version %q", s) } // ParseNonStrict attempts to parse a version in non-strict mode. It supports // the same patterns as Parse with the addition of some extra patterns that // are not considered pure semantic version values. // // The following version patterns are accepted: // 1 (major) // 1.2 (major, minor) // 1.2.3 (major, minor, patch) // 1.2-tag (major, minor, tag) // 1.2-tag3 (major, minor, patch, tag) // 1.2.3.4 (major, minor, patch, build) // 1.2-tag3.4 (major, minor, patch, build) func ParseNonStrict(s string) (Number, error) { groups := captureNamedGroups(s, numberPat) if n := parseVersion(groups, false); n != nil { return *n, nil } return Number{}, fmt.Errorf("invalid version %q", s) } func parseVersion(groups map[string]string, strict bool) *Number { var n Number // Major is always required major := groups["major"] if major == "" { return nil } n.Major = atoi(major) // Minor is only required in strict mode minor := groups["minor"] if minor == "" && strict { return nil } else if minor != "" { n.Minor = atoi(minor) } // Patch is only required in strict mode. However there can be two // possible patch groups depending on whether a tag is specified: // - "patch" captures a standalone patch version (e.g. 1.2.3) // - "patchInTag" captures a patch version as a suffix to tag (e.g. 1.2-tag3) patch := groups["patch"] if patch == "" { patch = groups["patchInTag"] // try the alternative } if patch == "" && strict { return nil } else if patch != "" { n.Patch = atoi(patch) } // Tag is always optional n.Tag = groups["tag"] // Build is always optional build := groups["build"] if build != "" { n.Build = atoi(build) } return &n } func captureNamedGroups(s string, re *regexp.Regexp) map[string]string { match := re.FindStringSubmatch(s) results := map[string]string{} groups := re.SubexpNames() for i, name := range match { results[groups[i]] = name } return results } // atoi is the same as strconv.Atoi but assumes that // the string has been verified to be a valid integer. func atoi(s string) int { n, err := strconv.Atoi(s) if err != nil { panic(err) } return n } // String returns the string representation of this Number. func (n Number) String() string { var s string if n.Tag == "" { s = fmt.Sprintf("%d.%d.%d", n.Major, n.Minor, n.Patch) } else { s = fmt.Sprintf("%d.%d-%s%d", n.Major, n.Minor, n.Tag, n.Patch) } if n.Build > 0 { s += fmt.Sprintf(".%d", n.Build) } return s } // Compare returns -1, 0 or 1 depending on whether // n is less than, equal to or greater than other. // The comparison compares Major, then Minor, then Patch, then Build, using the first difference as func (n Number) Compare(other Number) int { if n == other { return 0 } less := false switch { case n.Major != other.Major: less = n.Major < other.Major case n.Minor != other.Minor: less = n.Minor < other.Minor case n.Tag != other.Tag: switch { case n.Tag == "": less = false case other.Tag == "": less = true default: less = n.Tag < other.Tag } case n.Patch != other.Patch: less = n.Patch < other.Patch case n.Build != other.Build: less = n.Build < other.Build } if less { return -1 } return 1 } // GetBSON implements bson.Getter. func (n Number) GetBSON() (interface{}, error) { return n.String(), nil } // SetBSON implements bson.Setter. func (n *Number) SetBSON(raw bson.Raw) error { var s string err := raw.Unmarshal(&s) if err != nil { return err } v, err := Parse(s) if err != nil { return err } *n = v return nil } // MarshalJSON implements json.Marshaler. func (n Number) MarshalJSON() ([]byte, error) { return json.Marshal(n.String()) } // UnmarshalJSON implements json.Unmarshaler. func (n *Number) UnmarshalJSON(data []byte) error { var s string if err := json.Unmarshal(data, &s); err != nil { return err } v, err := Parse(s) if err != nil { return err } *n = v return nil } // MarshalYAML implements yaml.v2.Marshaller interface func (n Number) MarshalYAML() (interface{}, error) { return n.String(), nil } // UnmarshalYAML implements the yaml.Unmarshaller interface func (n *Number) UnmarshalYAML(unmarshal func(interface{}) error) error { var vstr string err := unmarshal(&vstr) if err != nil { return err } v, err := Parse(vstr) if err != nil { return err } *n = v return nil } // ToPatch returns back a semver Number (Major.Minor.Tag.Patch), without a build // attached to the Number. // In some scenarios it's prefable to not have the build number to identity a // version and instead use a less qualified Number. Being less specific about // exactness allows us to be more flexible about compatible with other versions. func (n Number) ToPatch() Number { return Number{ Major: n.Major, Minor: n.Minor, Patch: n.Patch, Tag: n.Tag, } } // ParseMajorMinor takes an argument of the form "major.minor" and returns ints major and minor. func ParseMajorMinor(vers string) (int, int, error) { parts := strings.Split(vers, ".") major, err := strconv.Atoi(parts[0]) minor := -1 if err != nil { return -1, -1, fmt.Errorf("invalid major version number %s: %v", parts[0], err) } if len(parts) == 2 { minor, err = strconv.Atoi(parts[1]) if err != nil { return -1, -1, fmt.Errorf("invalid minor version number %s: %v", parts[1], err) } } else if len(parts) > 2 { return -1, -1, fmt.Errorf("invalid major.minor version number %s", vers) } return major, minor, nil } version-2.0.1/version_test.go000066400000000000000000000226451427063102400162620ustar00rootroot00000000000000// Copyright 2012, 2013 Canonical Ltd. // Licensed under the LGPLv3, see LICENCE file for details. package version_test import ( "encoding/json" "strings" "github.com/juju/mgo/v3/bson" jc "github.com/juju/testing/checkers" gc "gopkg.in/check.v1" goyaml "gopkg.in/yaml.v3" "github.com/juju/version/v2" ) type suite struct{} var _ = gc.Suite(&suite{}) func (*suite) TestCompare(c *gc.C) { cmpTests := []struct { v1, v2 string compare int }{ {"1.0.0", "1.0.0", 0}, {"01.0.0", "1.0.0", 0}, {"10.0.0", "9.0.0", 1}, {"1.0.0", "1.0.1", -1}, {"1.0.1", "1.0.0", 1}, {"1.0.0", "1.1.0", -1}, {"1.1.0", "1.0.0", 1}, {"1.0.0", "2.0.0", -1}, {"1.2-alpha1", "1.2.0", -1}, {"1.2-alpha2", "1.2-alpha1", 1}, {"1.2-alpha2.1", "1.2-alpha2", 1}, {"1.2-alpha2.2", "1.2-alpha2.1", 1}, {"1.2-beta1", "1.2-alpha1", 1}, {"1.2-beta1", "1.2-alpha2.1", 1}, {"1.2-beta1", "1.2.0", -1}, {"1.2.1", "1.2.0", 1}, {"2.0.0", "1.0.0", 1}, {"2.0.0.0", "2.0.0", 0}, {"2.0.0.0", "2.0.0.0", 0}, {"2.0.0.1", "2.0.0.0", 1}, {"2.0.1.10", "2.0.0.0", 1}, } for i, test := range cmpTests { c.Logf("test %d: %q == %q", i, test.v1, test.v2) v1, err := version.Parse(test.v1) c.Assert(err, jc.ErrorIsNil) v2, err := version.Parse(test.v2) c.Assert(err, jc.ErrorIsNil) compare := v1.Compare(v2) c.Check(compare, gc.Equals, test.compare) // Check that reversing the operands has // the expected result. compare = v2.Compare(v1) c.Check(compare, gc.Equals, -test.compare) } } func (*suite) TestCompareAfterPatched(c *gc.C) { cmpTests := []struct { v1, v2 string compare int }{ {"1.0.0", "1.0.0", 0}, {"01.0.0", "1.0.0", 0}, {"10.0.0", "9.0.0", 1}, {"1.0.0", "1.0.1", -1}, {"1.0.1", "1.0.0", 1}, {"1.0.0", "1.1.0", -1}, {"1.1.0", "1.0.0", 1}, {"1.0.0", "2.0.0", -1}, {"1.2-alpha1", "1.2.0", -1}, {"1.2-alpha2", "1.2-alpha1", 1}, {"1.2-alpha2.1", "1.2-alpha2", 0}, {"1.2-alpha2.2", "1.2-alpha2.1", -1}, {"1.2-beta1", "1.2-alpha1", 1}, {"1.2-beta1", "1.2-alpha2.1", 1}, {"1.2-beta1", "1.2.0", -1}, {"1.2.1", "1.2.0", 1}, {"2.0.0", "1.0.0", 1}, {"2.0.0.0", "2.0.0", 0}, {"2.0.0.0", "2.0.0.0", 0}, {"2.0.0.1", "2.0.0.0", 0}, {"2.0.1.10", "2.0.0.0", 1}, } for i, test := range cmpTests { c.Logf("test %d: %q == %q", i, test.v1, test.v2) v1, err := version.Parse(test.v1) c.Assert(err, jc.ErrorIsNil) v2, err := version.Parse(test.v2) c.Assert(err, jc.ErrorIsNil) compare := v1.ToPatch().Compare(v2) c.Check(compare, gc.Equals, test.compare) // Check that reversing the operands has // the expected result. compare = v2.Compare(v1.ToPatch()) c.Check(compare, gc.Equals, -test.compare) } } var parseTests = []struct { v string err string expect version.Number }{{ v: "0.0.0", }, { v: "0.0.1", expect: version.Number{Major: 0, Minor: 0, Patch: 1}, }, { v: "0.0.2", expect: version.Number{Major: 0, Minor: 0, Patch: 2}, }, { v: "0.1.0", expect: version.Number{Major: 0, Minor: 1, Patch: 0}, }, { v: "0.2.3", expect: version.Number{Major: 0, Minor: 2, Patch: 3}, }, { v: "1.0.0", expect: version.Number{Major: 1, Minor: 0, Patch: 0}, }, { v: "10.234.3456", expect: version.Number{Major: 10, Minor: 234, Patch: 3456}, }, { v: "10.234.3456.1", expect: version.Number{Major: 10, Minor: 234, Patch: 3456, Build: 1}, }, { v: "10.234.3456.64", expect: version.Number{Major: 10, Minor: 234, Patch: 3456, Build: 64}, }, { v: "10.235.3456", expect: version.Number{Major: 10, Minor: 235, Patch: 3456}, }, { v: "1.21-alpha1", expect: version.Number{Major: 1, Minor: 21, Patch: 1, Tag: "alpha"}, }, { v: "1.21-alpha1.1", expect: version.Number{Major: 1, Minor: 21, Patch: 1, Tag: "alpha", Build: 1}, }, { v: "1.21-alpha1", expect: version.Number{Major: 1, Minor: 21, Patch: 1, Tag: "alpha", Build: 1}.ToPatch(), }, { v: "1.21-alpha10", expect: version.Number{Major: 1, Minor: 21, Patch: 10, Tag: "alpha"}, }, { v: "1.21.0", expect: version.Number{Major: 1, Minor: 21}, }, { v: "1234567890.2.1", err: "invalid version.*", }, { v: "0.2..1", err: "invalid version.*", }, { v: "1.21.alpha1", err: "invalid version.*", }, { v: "1.21-alpha", err: "invalid version.*", }, { v: "1.21-alpha1beta", err: "invalid version.*", }, { v: "1.21-alpha-dev", err: "invalid version.*", }, { v: "1.21-alpha_dev3", err: "invalid version.*", }, { v: "1.21-alpha123dev3", err: "invalid version.*", }} func (*suite) TestParse(c *gc.C) { for i, test := range parseTests { c.Logf("test %d: %q", i, test.v) got, err := version.Parse(test.v) if test.err != "" { c.Assert(err, gc.ErrorMatches, test.err) } else { c.Assert(err, jc.ErrorIsNil) c.Assert(got, gc.Equals, test.expect) c.Check(got.String(), gc.Equals, test.v) } } } var parseNonStrictTests = []struct { v string err string expect string }{{ v: "1", expect: "1.0.0", }, { v: "1.2", expect: "1.2.0", }, { v: "1.2-alpha", expect: "1.2-alpha0", }, { v: "1.", err: "invalid version.*", }, { v: "1.2-", err: "invalid version.*", }} func (*suite) TestParseNonStrict(c *gc.C) { for i, test := range parseNonStrictTests { c.Logf("test %d: %q", i, test.v) got, err := version.ParseNonStrict(test.v) if test.err != "" { c.Assert(err, gc.ErrorMatches, test.err) } else { c.Assert(err, jc.ErrorIsNil) c.Check(got.String(), gc.Equals, test.expect) } } } func binaryVersion(major, minor, patch, build int, tag, series, arch string) version.Binary { return version.Binary{ Number: version.Number{ Major: major, Minor: minor, Patch: patch, Build: build, Tag: tag, }, Release: series, Arch: arch, } } func (*suite) TestParseBinary(c *gc.C) { parseBinaryTests := []struct { v string err string expect version.Binary }{{ v: "1.2.3-ubuntu-amd64", expect: binaryVersion(1, 2, 3, 0, "", "ubuntu", "amd64"), }, { v: "1.2-tag3-windows-amd64", expect: version.Binary{ Number: version.Number{ Major: 1, Minor: 2, Patch: 3, Build: 4, Tag: "tag", }.ToPatch(), Release: "windows", Arch: "amd64", }, }, { v: "1.2.3.4-ubuntu-amd64", expect: binaryVersion(1, 2, 3, 4, "", "ubuntu", "amd64"), }, { v: "1.2-alpha3-ubuntu-amd64", expect: binaryVersion(1, 2, 3, 0, "alpha", "ubuntu", "amd64"), }, { v: "1.2-alpha3.4-ubuntu-amd64", expect: binaryVersion(1, 2, 3, 4, "alpha", "ubuntu", "amd64"), }, { v: "1.2.3", err: "invalid binary version.*", }, { v: "1.2-beta1", err: "invalid binary version.*", }, { v: "1.2.3--amd64", err: "invalid binary version.*", }, { v: "1.2.3-ubuntu-", err: "invalid binary version.*", }} for i, test := range parseBinaryTests { c.Logf("first test, %d: %q", i, test.v) got, err := version.ParseBinary(test.v) if test.err != "" { c.Assert(err, gc.ErrorMatches, test.err) } else { c.Assert(err, jc.ErrorIsNil) c.Assert(got, gc.Equals, test.expect) } } for i, test := range parseTests { c.Logf("second test, %d: %q", i, test.v) v := test.v + "-ubuntu-amd64" got, err := version.ParseBinary(v) expect := version.Binary{ Number: test.expect, Release: "ubuntu", Arch: "amd64", } if test.err != "" { c.Assert(err, gc.ErrorMatches, strings.Replace(test.err, "version", "binary version", 1)) } else { c.Assert(err, jc.ErrorIsNil) c.Assert(got, gc.Equals, expect) } } } var marshallers = []struct { name string marshal func(interface{}) ([]byte, error) unmarshal func([]byte, interface{}) error }{{ "json", json.Marshal, json.Unmarshal, }, { "bson", bson.Marshal, bson.Unmarshal, }, { "yaml", goyaml.Marshal, goyaml.Unmarshal, }} func (*suite) TestBinaryMarshalUnmarshal(c *gc.C) { for _, m := range marshallers { c.Logf("encoding %v", m.name) type doc struct { Version *version.Binary } // Work around goyaml bug #1096149 // SetYAML is not called for non-pointer fields. bp := version.MustParseBinary("1.2.3-ubuntu-amd64") v := doc{&bp} data, err := m.marshal(&v) c.Assert(err, jc.ErrorIsNil) var bv doc err = m.unmarshal(data, &bv) c.Assert(err, jc.ErrorIsNil) c.Assert(bv, gc.DeepEquals, v) } } func (*suite) TestNumberMarshalUnmarshal(c *gc.C) { for _, m := range marshallers { c.Logf("encoding %v", m.name) type doc struct { Version *version.Number } // Work around goyaml bug #1096149 // SetYAML is not called for non-pointer fields. np := version.MustParse("1.2.3") v := doc{&np} data, err := m.marshal(&v) c.Assert(err, jc.ErrorIsNil) var nv doc err = m.unmarshal(data, &nv) c.Assert(err, jc.ErrorIsNil) c.Assert(nv, gc.DeepEquals, v) } } func (*suite) TestParseMajorMinor(c *gc.C) { parseMajorMinorTests := []struct { v string err string expectMajor int expectMinor int }{{ v: "1.2", expectMajor: 1, expectMinor: 2, }, { v: "1", expectMajor: 1, expectMinor: -1, }, { v: "1.2.3", err: "invalid major.minor version number 1.2.3", }, { v: "blah", // NOTE: This error won't match on <=go1.9 err: `invalid major version number blah: strconv.Atoi: parsing "blah": invalid syntax`, }} for i, test := range parseMajorMinorTests { c.Logf("test %d", i) major, minor, err := version.ParseMajorMinor(test.v) if test.err != "" { c.Check(err, gc.ErrorMatches, test.err) } else { c.Check(err, jc.ErrorIsNil) c.Check(major, gc.Equals, test.expectMajor) c.Check(minor, gc.Equals, test.expectMinor) } } }